【问题标题】:Search By date in jqgrid Search Toolbar not working在 jqgrid 搜索工具栏中按日期搜索不起作用
【发布时间】:2012-11-05 06:16:33
【问题描述】:

我在 Asp.net 中使用 Jqgrid。我正在尝试实现 Toolbar Search 。每个字段都是可搜索的,但日期搜索不起作用。我看到了一些示例,它们正在工作,因为它们使用本地数据并且源中的日期格式为 2012/02/02。但我是直接从数据库中获取数据,所以请帮我解决这个问题。

这是我的 Date Col 模块

               name:'Date',
               index:'Date',                                                                                  
               align:"center",
               formatter:'date',                                                                 
               formatoptions: {newformat:'m/d/Y'},                               
               searchoptions: 
               {sopt: ['eq','ne'],
               dataInit : function (elem) {
$(elem).datepicker({ changeYear: true, changeMonth: true,  showButtonPanel: true});
                                        }}

【问题讨论】:

  • 您从服务器返回的'Date' 列的信息究竟是哪种格式?你用的是哪个datatype?你用loadonce: true还是不用?
  • 数据类型=日期时间,加载一次=真
  • 参数datetype可以是"json""xml""local"等等? jqGrid 没有load onceData type 选项。只有loadoncedatetype。所有错误的写入参数将被忽略。例如,您如何发送今天的日期?您是使用"2012-11-05" 还是以其他格式发送的?
  • 数据类型为“json”,格式为mm/dd/yyy--11/05/2012

标签: asp.net json search jqgrid


【解决方案1】:

您应该在'Date' 列的定义中使用附加属性sorttype: "date"。此外,您应该验证服务器是否以正确的格式返回日期值。

如果您只使用formatoptionsnewformat 属性,那么 jqGrid 尝试读取 ISO 8601 格式的数据:“Y-m-d”。如果服务器以另一种格式返回日期,您应该描述关于formatoptions 的附加srcformat 属性的格式。例如srcformat: "m/d/Y"

【讨论】:

  • 我添加了 sorttype: "date" 但它仍然无法正常工作,并且从服务器返回的日期如下所示"11/5/2012 12:00:00 AM"。
猜你喜欢
  • 2012-03-22
  • 1970-01-01
  • 1970-01-01
  • 2014-04-19
  • 2012-06-04
  • 1970-01-01
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多