There are many ways how to solve the problem. The source format srcformat: 'U'
means (like other formats used by jqGrd) PHP format. Starting with PHP 5.2.2 it supports "u"
format, but it means microseconds (μs) instead of milliseconds (ms) which you use (see here for example). So the input data should be integer or float value with is 1/1000 milliseconds to be successful processed by srcformat: 'U'
. What jqGrid do to parse srcformat: "U"
format will be clear from the following (see here) lines of the code
if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
timestamp = new Date( parseFloat(date)*1000 );
}
So you need just adjust the values which you use as the input for srcformat: "U"
.
UPDATED: If your input data are like 1394085600000
and if you can't change it then you can use custom formatter which calls "date" formatter:
formatter: function (cellval, opts, rowObject, action) {
return $.fn.fmatter.call(
this,
"date",
new Date(cellval),
$.extend({}, $.jgrid.formatter.date, opts),
rowObject,
action);
}
See the demo which use it.
UPDATED 2: Free jqGrid fork support new format option: srcformat: "u1000"
, which converts the date in long integer format like 1394085600000
in "03/06/2014"
. Thus to solve the problem one should just upgrade to the current version of free jqGrid. See the demo or the answer
I have to warn about the usage of pseudo-format srcformat: 'U/1000'
. jqGrid (neither old or the new one) support the format. It can be used as a hack to display only the date, but other functionality will not work correctly (editing, filtering, sorting and so on) or don't work even for reading in some web browsers (see the question). Thus I strictly recommend don't use the hack whith srcformat: 'U/1000'
.