使用jqGrid对日期进行排序时出现问题.给定以下日期
jqGrid对我的日期进行如下排序:
01/01/2010 01/01/2011 01/02/2010 01/02/2011我希望看到
01/01/2010 01/02/2010 01/01/2011 01/02/2011我的日期格式为dd/mm/yyyy,我有以下格式选项-
{ name: 'myDate', index: 'myDate', sortable: true, sorttype: 'date' }我在这里错过了什么吗?或者这是jqGrid的限制吗?
解决方案您犯了典型的错误.问题在于jqGrid希望以 ISO 8601 日期格式输入日期:Ymd.
如果以"dd/mm/yyyy"格式发布jqGrid的输入数据,则应添加 datefmt: 'm/d/Y'属性到列定义.
最好的方法是以ISO格式填充网格的日期数据,并以任何其他格式转换输入,仅使用以下设置在jqGrid中显示日期
formatter:'date', formatoptions: {newformat:'m/d/Y'}, datefmt: 'd-M-Y'比较树演示的源代码:此,此和此.
I have an issue when sorting dates using jqGrid. Given the following dates
jqGrid is sorting my dates as follows:
01/01/2010 01/01/2011 01/02/2010 01/02/2011I would expect to see
01/01/2010 01/02/2010 01/01/2011 01/02/2011My date format is dd/mm/yyyy and I have the follow format options -
{ name: 'myDate', index: 'myDate', sortable: true, sorttype: 'date' }Have I missed something here or is this a limitation of the jqGrid?
解决方案You made the typical error. The problem is that jqGrid expects the input of dates in the ISO 8601 date format: Y-m-d.
If you post the input data of jqGrid in the "dd/mm/yyyy" format you should add datefmt: 'm/d/Y' property to the column definition.
The best way would be to fill the date data of the grid in the ISO format and to convert the input in any other format only to display the date in jqGrid using the following settings
formatter:'date', formatoptions: {newformat:'m/d/Y'}, datefmt: 'd-M-Y'Compare the source code of the tree demos: this, this and this.
更多推荐
jqGrid无法正确排序日期
发布评论