jQuery Grid v 15.1.20151.1005
I'm binding the JSON results of an AJAX query to the grid as follows:
$.ajax({ type : 'GET', url : env_constants.DATASERVICES_URL + '/ar_invoices', data : params, dataType : 'json', success : function(invoiceRows) { $("#ar_invoices").igGrid("option", "dataSource", invoiceRows); $("#ar_invoices").igGrid( "resizeContainer" ); }, error : function(jqXHR, textStatus, errorThrown) { alert(jqXHR.responseText); } });
When I examine the first object of invoiceRows in the browser's debugger I see this field: { invoiceDate : "2015-07-25" }
However, the grid displays this date as "07/24/2015". Similarly, the date 8/1/2015 is displayed as "7/31/2015".
Could the grid be parsing this date format wrong? Perhaps applying a timezone adjustment to it?
Thanks,
Matt
Hello Matthew,
Thank you for your feedback.
If I can provide you with further assistance, please let me know.
Regards,
Tsanna
Thanks for the explanation, and the useful link.
In our case, both the server and the client are in the same timezone! But the server is sending a plain date, which the client is then misinterpreting as being in a different timezone. (Again, I think dates that have no timezones on them should be considered local, not UTC.)
Some of my frustration is that I'm used to programming languages that (unlike JS) don't treat all dates as date-times. It seems weird to me that I can't have a "simple" date field with no time on it. The user can enter an absolute date like their birthday, only to see it converted to another date. But I guess that's not really the grid's fault.
So I'm not completely convinced the grid's interpretation of vanilla dates from the server is correct, but I do understand its behavior better now. I can work around it with the enableUTCDates option, or by appending a timezone suffix to the dates I'm getting from the service.
Thanks again for the explanations.
In general when a date is created on the client-side it’s created in the local time zone.For example, if you create a new date on the client side: new Date(“09/09/2015”); You’ll see that the created date object will have the timezone offset of your timezone, so for example, if you’re in a timezone with GTM+3:00 that will be reflected in the created date object and you’ll get:Wed Sep 09 2015 00:00:00 GMT+0300 (FLE Daylight Time)
Now, this date will not be same as the one you send from the server, if you’ve send a UTC date (a date without any timezone offsets). To account for that difference, the grid has an enabledUTCDates option( which is false by default), which when enabled will format that client date to UTC ( so for example the date from before will be -3:00 hours to account for the offset of GMT+0300).
This is where the difference in the date you see comes from. The following topic explains the whole process in more details:http://www.igniteui.com/help/using-igniteui-controls-in-different-time-zones Please let me know if you have any further questions.
Edited: my followup post that was here was confused and made some assumptions. I am removing it. Apologies for any inconvenience. I will make a new post if something develops.
My post above is still valid I think, and I welcome responses to it. Thanks!
Tsanna,
enableUTCDates does fix it.
I'd like to understand why this works though. The grid is being passed "YYYY-MM-DD". The grid seems to be assuming that incoming date strings are UTC if they have no timezone on them (i.e. no Z suffix, and no "+h:00" specified). So the grid converts it to local time if enableUTCDates=false. Is my interpretation right?
(FYI if I'm understanding the ISO 8601 standard correctly this may be a bug. I think if there is no Z suffix or explicit timezone, then the time should already be assumed to be in local time.)