I'm using jqgrid 4.1.2 version and the server returns date serialized into JSON as below "\/Date(1314443359000-0700)\/"
.
The problem is jqgrid is not displaying the server开发者_如何学Python datetime but it displays datetime based on local time zone also when I change my local time zone the displayed datetime differs. How I can display the server datetime in jqgrid?
I stuck with the same issue as yours. JQGrid is just trying to be smart here. And java script serializer which is default from Microsoft is a real culprit. You just need to send date in standard format thats it. And that will work like anything. Further details are nicely explained over here
As, a simplest solution just use Json.net and things will be solved without messing up the code or doing changes in datetime over client side.
Hope, answer helps you, please let me know if any further details are needed.
What you described is the correct behavior. It is the same time moment as in the server. If we both want talk on phone at the same time we have to place the local time in our outlook calender to be ready at the same moment to speak.
If you need another implementation of the date conversion you can use custom formatter.
UPDATED: You can define you myEditSerialize
function and use if as serializeEditData or as serializeRowData. Th can be defined as the following
var myEditSerialize = function (data) {
var obj = $.extend({}, data);
obj.RolloutTermin = jQuery.datepicker.parseDate('dd.mm.yy', data.RolloutDate);
if (Date.isInstanceOfType(obj.RolloutDate)) {
obj.RolloutDate= '\/Date(' + obj.RolloutDate.getTime() + ')\/';
}
return JSON.stringify(obj);
}
In the example I make date serialization from the column 'RolloutDate' so that it will be converted to the DateTime
on the server side. If you would use Sys.Serialization.JavaScriptSerializer.serialize(data)
directly all will works also. I prefer better to use JSON.stringify
function from json2.js.
this work:
colModel:[
...,sorttype:"date",formatter: function (cellval, opts) {
var date = new Date(cellval);
opts = $.extend({}, $.jgrid.formatter.date, opts);
return $.fmatter.util.DateFormat("", date, 'd-M-Y h:i:s', opts);
},...
]
精彩评论