Hi,
My dates in the grid are being displayed one day behind even though I have set the EnableUtcDates(true).
I have enabled UTCDates in my grid model through the MVC GridModel() method like this :
GridModel GetGridModel(selectedRow) {
GridModel gridModel = new GridModel(); gridModel.ID = "MyGrid"; gridModel.AutoGenerateColumns = false; gridModel.PrimaryKey = selectedRow.PrimaryKey; gridModel.Width = "100%"; gridModel.Height = "400px"; gridModel.EnableUTCDates = true;
.... ....// other settings
..... ......
return gridModel;
}
1) The date I get from server is 7/1/2012 00:00:00.000 & the grid displays 6/30/2012 (Here the month & day both are decremented because of 1st date)
2) The date I get from server is 11/11/2014 00:00:00.000 & the grid displays 11/10/2014 (Here only the day is decremented)
---------------
This issue is also discussed here but the answer suggests to enable UTCDates feature of the grid.
http://ko.infragistics.com/community/forums/t/80982.aspx
I have enabled UtcDates, I am still facing the issue. What am I doing wrong?
Thanks.
Hi zep lin,
Thank you for posting in our forums!
I will need a little more time to investigate why the dates continue to be offset while EnableUTCDates is true. First, please answer the following questions for me so I may better assist you with this:
1.) Which version and build of IgniteUI you are using. e.g. 14.1.20141.2249
2.) How is the Date being passed into the grid? Are you sending it directly as JSON from the server?
Looking forward to hearing from you.
Thanks Michael for the response.
1) I am using 2013.2 version of infragistics. Version 4.13.2.2157
2) This method converts my collection to json and then passes it on to the grid:
public ActionResult ConvertToJson<T>(ResponseWrapper<T> result) { ResponsePacket<T> dataViewModel = new ResponsePacket<T>(); JsonResult jsonResult = new JsonResult(); var pageSize = HttpUtility.ParseQueryString(Request.Url.Query).Get("pageSize"); var pageIndex = HttpUtility.ParseQueryString(Request.Url.Query).Get("page"); if (pageSize == null || pageIndex == null) { dataViewModel.Records = result.Content; dataViewModel.RecordCountKey = result.recordCountKey; jsonResult.Data = dataViewModel.Records; jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet; } else { dataViewModel.Records = result.Content.AsQueryable(); dataViewModel.RecordCountKey = result.recordCountKey; jsonResult.Data = dataViewModel; jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet; } return jsonResult; }
The grid model is set up on my controller & the gridModel is generic in a way that it is for all the entities & the columns are set up dynamically like this :
gridModel.Columns.Add(new GridColumn() {
//record is my result set which contains the MetaData of the database table HeaderText = record.DisplayName, Key = record.ColumnName, DataType = record.DataType });
Hello Zep,
You can use a formatter function to workaround this.
Please review the attached sample.
Thanks I will implement it in 3-4 days and let you know how it goes. Thanks for the help.
I will be awaiting your feedback.
Hello,
I'm just following up to see if you need any further assistance with this issue. If so please let me know.
Hello Denis,
I implemented your solution, Its not working for me. The following was the result I was getting BEFORE implementing your soultion:
The date on the server is : 2014-11-12 00:00:00.000
The date in the grid is : 11/11/2014 _7:00 PM
(12th date becomes 11th)
After I implemented your sample project I get a completely wrong date, I cant figure out the implementation details of your formatToServerTimeZone(date) function, is it specific to Pennsylvania? Are Daylight Savings setting different for every region ? Then this would be a problem. I dont want to hardcode the daylight saving settings. The following line does not make sense to me and if I have to modify it according to my region then this would become region specific, I dont think there is Daylight Saving in my country right now so what should be the setting?
Also one more thing.
I have a form (Master) also above the grid (Detail) . The same date 2014-11-12 00:00:00.000 from server is loaded in the form's datePicker and the date is displayed correctly like this : 11/12/2014
There is an event bound to this datePicker, on its selection changed event, the date of this (master's) datePicker is used to set the date in my Grid (detail). And the date 11/12/2014 becomes 11/11/2014 _7:00 PM . And if I commit the data the server's date also becomes 11/11/2014 00:00:00.000 BUT if I use the datePicker inside the grid (detail) and select 11/12/2014 then the correct date is displayed in the grid as well as on committing the row the server's date becomes 2014-11-12 14:00:00.000 and is displayed correctly next time in the grid.
From what I understand is that if I change the grid's date column through my master's datePicker, the date becomes one day behind, If I set the date through the grid's columns datePicker the date displays alright and the server also stores it correctly.
var date = $("#voucherPartyRefDate").igEditor("value"); // get date from master's datePicker
$("#voucherDetailGrid").igGridUpdating("updateRow", detailHeaderPk, { //set date of detail(grid's) datePicker
vchr_dtl_ref_dt: date
-----------------------------------
If this is messing up the date than what should be done ? Is there another way to set the date of grid date column based on the date selected from master's igDatePicker?
If you’re using also any of the editor controls (igDatePicker and igDateEditor) you should also set EnableUTCDates to true for them as well in order to have consistent dates from the same time zone.
I was facing the same problem. The issue was this: I had enabled UTCDates in the grid but I hadnt set UTCDates in my igEditor therfore the value I set from igEditor was being set as one day behind in the igGrid. Thanks for the question & your help. Appreciate it.
Have you been able to resolve the issue? If not so I am still awaiting your sample project.
Hello zep lin,
The EnableUTCDates option only formats the date it received from the server to UTC.
Basically the date values go through a formatter method that depending on the EnableUTCDates option either builds the value with the standard date object methods in local time (getFullYear(), getMonth(), getDate(),getHours() etc.) or via the methods UTC equivalents in UTC time ( getUTCFullYear(), getUTCMonth(), getUTCDate(), getUTCHours() etc.). The formatted value is what you’ll see in the cells of the grid once it's rendered.
This is also true for the igDatePicker and igDateEditor.
In your case most probably the dates you send from the backend are not in UTC (DateTime.Kind is not UTC but Local) which means that they have their own offset from UTC which will not be taken into consideration in cases where the Json data is manually retuned from an action result.
Best Regards,
Maya Kirova
Product Developer
Infragistics, Inc.
http://ko.infragistics.com/support
Provide isolated sample project replicating your issue so I can be able to investigate this behavior.