当将日历时间(以毫秒为单位)显示为日期时,jqGrid不排序

时间:2011-12-01 13:01:47

标签: json jqgrid epoch

我使用jqGrid,我的网格定义是这样的:

...
colNames:['Type','Date','Message','User Name','Host'],
colModel:[{name:'type',index:'type', width:100},
{name:'date',index:'date', sorttype:'date', formatter:'date', 
  formatoptions: {newformat:'d-M-Y'}, width:100},
{name:'log',index:'log', width:200},
{name:'username',index:'username', width:50},
{name:'host',index:'host', width:50}], 
...

当我调试我的即将到来的数据时,其中一个日期值(它是Number)如下:

1322550786997

网格显示如下:

29-Nov-2011

到目前为止,一切都还行。但是,当我想对日期列进行排序时,它不会改变任何内容。

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

问题是解码Unix(formatoptions: {srcformat: 'U', newformat: 'd-M-Y'})日期1322550786997会让我们19-Dec-43879而不是29-Nov-2011。您对日期的正确表示将是字符串"\/Date(1322550786997)\/",而不是数字1322550786997

请参阅the demo

enter image description here

更新:您还可以使用以下自定义格式化程序作为解决方法

formatter: function (cellval, opts) {
    var date = new Date(cellval);
    opts = $.extend({}, $.jgrid.formatter.date, opts);
    return $.fmatter.util.DateFormat("", date, 'd-M-Y', opts);
}

创建Date,然后使用原始date格式化程序将其转换为格式'd-M-Y'。请参阅here演示。