我知道这里有大量的这类问题的答案,但他们似乎都有一些独特的情况。但在我的情况下,它应该是一个非常简单的事情,因为我没有对日期做任何奇怪的事情,但我无法使日期排序工作。jqGrid日期排序(本地)不起作用
这是我从JSON获得的数据(部分编辑,因为这是一个公司项目)。
{"rows": [
{"cell": [ "140935", ..., "19/06/2013 3:17:02 PM", ... ]},
{"cell": [ "140894", ..., "19/06/2013 10:01:57 AM", ... ]},
{"cell": [ "140803", ..., "18/06/2013 11:50:01 AM", ... ]},
{"cell": [ "140008", ..., "10/06/2013 12:44:44 PM", ... ]},
{"cell": [ "138280", ..., "28/05/2013 11:57:19 AM", ... ]},
{"cell": [ "118286", ..., "15/11/2012 7:13:19 PM", ... ]}
]}
所以,你可以看到,当我从服务器得到它已经排序。麻烦的是,当我在表格中使用排序时,它被搞砸了,而2013年5月28日的日期比6月份的日期更晚。这是screenshto。
这里是我用来生成这个jqGrid代码(为简洁起见,我部分编辑了它,但我不认为我会删除任何会影响此问题的东西)。
我首先设置了列名和列模型作为变量,以保持整洁。
cnames = ['ID', _company, _location, ... _createdon..],
cmodel = [
{ name:'ticketId', index:'ticketId', key:true, width:60, align:'center',
sorttype:'int', fixed:true, resizable:false, editrules:{ edithidden:true }
},
{ name:'company', index:'company', width:117, editrules:{edithidden:true} },
{ name:'location', index:'location', width:94, editrules:{edithidden:true} },
...
{ name:'CreatedOn', index:'CreatedOn', width:85, sorttype:'date',
datefmt:'m/d/Y h:i:s A', fixed:true, editrules:{edithidden:true, date:true} },
...
]
所以日期格式m/d/Y h:i:s A
的最新数据,我从服务器获取15/11/2012 7:13:19 PM
匹配。
我然后加载的jqGrid这样
ticketsTable = tableWrap.jqGrid({
url: urlTicketHandler + '?method=GetTickets&' + filtersData,
mtype: 'GET',
datatype: 'json',
colNames: cnames,
colModel: cmodel,
height: 'auto',
rowNum: 1000,
autowidth: true,
sortname: 'priority',
sortorder: 'desc',
pgbuttons: false,
pginput: false,
pgtext: '',
viewrecords: true,
altRows: true,
loadonce: true,
scrollOffset: 0,
hidegrid: false,
caption: _tickets,
toppager: true,
pager: '#ticketsList_footer',
prmNames: {page:null, rows:null, search:null},
viewsortcols: [true,'vertical',true],
recordtext: _showingxt + ' {2} ' + _tickets,
gridview: true,
ignoreCase: true,
multiselect: hasFullAccess,
loadComplete: function(d) {
if (firstLoad) {
firstLoad = false;
if (isColState && myColumnsState.permutation.length) {
$(this).jqGrid("remapColumns", myColumnsState.permutation, true);
}
}
saveColumnState.call($(this), this.p.remapColumns);
}
});
在这里,我想可能造成的任何问题的唯一的事情是列节省部分(我这里没有包括整个功能,但我不知道它是实际上是相关的,我从jqGrid自己的网站上获取)。
我省略了其他列上的某些格式,但我没有触及日期列。我也省略了一些功能来为表格添加自定义按钮,但是我认为这不重要。
我在这里失踪的任何东西?