【问题标题】:jqgrid date sorting and formattingjqgrid日期排序和格式化
【发布时间】:2011-09-22 12:54:33
【问题描述】:

我需要以 mm/dd/yyyy 和 mm/dd/yyyy hh:mm:ss 两种格式显示日期。我发现我们可以在 colmodel 中使用 formatoptions

formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/y'}

formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/y h:i:s'}

但我在 jqgrid 中得到输出为 mm/dd/yy。任何人都应提供解决方案如何显示 mm/dd/yyyy。我需要对两列进行排序。

提前致谢

【问题讨论】:

    标签: sorting date jqgrid formatting


    【解决方案1】:

    您可以使用 'Y' 而不是 'y' 将年份显示为 'yyyy' 而不是 'yy':

    formatter:'date', formatoptions: {srcformat:'ISO8601Long', newformat:'m/d/Y H:i:s'}
    

    如果你想在 mounth 和 tha da 中没有前面的空值(没有 0 填充),你可以使用 'n/j/Y' 而不是 'm/d/Y'。您可以在格式化程序的the source code 中找到“日期”格式化程序支持的所有不同可能标志。

    已更新:问题是srcformat的简称,如ISO8601LongUniversalSortableDateTimeShortDate等(详见the documentation)可以使用仅适用于远程网格数据datatype:'json'datatype:xml)。为了使本地排序工作正确,您应该使用 srcformat:'ISO8601Long' 来代替 srcformat:'Y-m-d H:i:s'

    The demo 表明这样的更改将使本地排序正常工作。

    我认为srcformat 中的限制可以解释为 jqGrid 中的错误。所以我建议您在the trirand forum 中发布相应的错误报告。然后 Tony Tomov(jqGrid 的开发者)可以在 jqGrid 代码中进行相应的更改。

    【讨论】:

    • thanx oleg,但排序并没有发生。我的 colmodel 代码是 '{name:'invdate',index:'invdate',sorttype:'date', formatter:'date', formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/Y'} } ,' 我的数组数据是'{id:"1",invdate:"2007-10-01",name:"test"}'。我错过了任何房产吗?
    • @user669789:现在我了解您的主要问题并建议您使用srcformat:'Y-m-d H:i:s' 而不是srcformat:'ISO8601Long' 作为解决方法。我更新了我的答案。
    【解决方案2】:

    非常感谢....我尝试将 jqgrid 与远程数据(json 格式)绑定,我想将日期格式显示为 dd/mm/yyyy。使用以下选项后

    formatter:'date', formatoptions: {srcformat:'ISO8601Long', newformat:'d/m/Y'}

    效果很好。

    【讨论】:

      猜你喜欢
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 2012-06-17
      • 2015-12-03
      • 2013-05-30
      相关资源
      最近更新 更多