【问题标题】:JQGrid Compare Equal Date FormatJQGrid 比较相等日期格式
【发布时间】:2018-01-08 10:56:18
【问题描述】:

我有 jqGrid 4.15.3。我正在使用 filterToolbar 在列中进行搜索。我有 date 列,格式如下 "/Date(1515401700270)/"。比较参数是eq,ge。问题是 ge 工作正常,但是当使用 equal 搜索网格中的现有值时,它不显示任何内容。你有什么想法如何解决这个问题吗?这与模型的 srcFormat 有联系吗?

Value: /Date(1515401700270)/ -> does not work
Value: 2017-01-02 -> work

我使用的列模型是:

{ "search" : "true", "label" : "DateCreated", "name": "DateCreated", "width" : 140, "sorttype": "date", "formatter" : "date", "formatoptions" : { "newformat" : "d.m.Y" },  
"searchoptions" : { "clearSearch" : "false",  "sopt": ["eq","ge"], "dataInit" : "(function(el) { $(el).datepicker( { firstDay: 1, dateFormat: 'dd.mm.yy' } ); })  " } }]

【问题讨论】:

    标签: javascript jquery jqgrid


    【解决方案1】:

    问题的原因很容易解释。 Date(1515401700270) 真的不是2018-01-08,而是2018-01-08 09:55:00 GMT+0100"。即使是您显示完整日期作为四舍五入的日期,直到只有 jqGrid 仍将数据保留为原始日期的日期。在比较日期期间,将使用原始日期。

    要允许用户在此类日期使用“相等”操作,您有三个主要选项:

    1. 您更改服务器代码以将所有日期的时间设置为 00:00
    2. 您在DateCreated 列中添加jsonmap 属性以将输入值四舍五入到以00:00 为时间的日期。 jsonmap用于读取输入数据,对本地保存在jqGrid中的数据进行四舍五入
    3. 您可以通过添加customSortOperations 来定义自定义排序/过滤操作。它允许重新定义eq 日期的操作。您只需要定义 eq 以便它只比较年、月和日并忽略所有其他 .您可以在the wiki article 中查看该功能的描述。 The answer 包括 the demo,它演示了该方法。

    【讨论】:

      猜你喜欢
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      相关资源
      最近更新 更多