jqGrid无法正确排序日期 [英] jqGrid not sorting dates correctly

查看:278
本文介绍了jqGrid无法正确排序日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用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'

比较树演示的源代码: 解决方案

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无法正确排序日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆