【问题标题】:JQgrid sort by date that is sent as string by serverJQgrid 按日期排序,服务器以字符串形式发送
【发布时间】:2015-09-24 16:24:58
【问题描述】:

我的服务器以 string 格式向 javascript 发送日期

"csd":"08-SEP-2015"

我想按日期对这一列的数据进行排序。但是排序不起作用。

这是我的 colModel

{
                name: 'csd',
                index: 'csd',
                width: 110,
                align: 'left',
                sorttype: 'date',
                datefmt:'d-M-Y'
   }

更新1:

我正在使用 jqGrid 4.5.4 - jQuery Grid

添加说明:我不想格式化日期,我只是希望列可以按日期排序。

更新2:

我将定义更新为

{
                name: 'csd',
                index: 'csd',
                width: 110,
                align: 'left',
                sorttype: 'date',

                formatter:'date',
                formatoptions:{srcformat:'d-M-Y' , newformat:'d-M-Y'}
            }

但现在我在现场得到了NaN-undefined

将问题标记为关闭,答案位于:

JQgrid Sorting date on the client side with a specific format

【问题讨论】:

  • 你使用哪个版本的 jqGrid?
  • @oleg 我明天会检查并更新问题...
  • 一般来说,我可以直接说,我建议您在指定srcformatnewformat 的地方使用formatter: "date"formatoptions。您可以删除 datefmt 在这种情况下将被忽略。它应该可以解决您的问题,但结果可能会有所不同,具体取决于您使用的 jqGrid 版本。我建议您始终包含有关您使用的 jqGrid 分支的信息(free jqGridGuriddo jqGrid JS 或版本
  • @Oleg jqGrid 4.5.4 - jQuery Grid,这就是我正在使用的。
  • 您能否尝试将(至少是临时的)jqGrid 的 URL 替换为释放 jqGrid 4.9.2 的 URL(参见 the wiki)。您使用了非常糟糕格式的输入数据,其中包含特定于语言环境的文本(“SEP”)。这是旧版本 jqGrid 在解析此类日期时的错误。如果使用免费的 jqGrid 4.9.2 解决了这个问题,那么 jqGrid 4.5.4 仍然包含旧的错误。

标签: jquery jqgrid


【解决方案1】:

使用特定于语言的格式来传输数据是不好的。 d-M-Y 的格式取决于区域设置。我不是 PHP 开发人员,但看到 PHP 有 setlocale() 和日期/时间函数应该取决于语言环境。同样,formatter: "date" 使用的格式 d-M-Y 也取决于区域设置,并且您将获得不同的结果取决于您使用的区域设置(尝试 grid.locale-de.jsgrid.locale-ru.jsgrid.locale-jp.js 等等)。

我建议您使用 ISO 8601 格式:在最简单的情况下,它将 08-SEP-2015 显示为 2015-09-08。

【讨论】:

    猜你喜欢
    • 2014-02-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 1970-01-01
    • 2021-06-13
    相关资源
    最近更新 更多