jqGrid无法正确排序日期

编程入门 行业动态 更新时间:2024-10-28 06:21:23
本文介绍了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'

比较树演示的源代码:此,此和此.

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/2011

I would expect to see

01/01/2010 01/02/2010 01/01/2011 01/02/2011

My 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无法正确排序日期

本文发布于:2023-10-28 02:34:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   日期   jqGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!