我需要以两种格式显示日期,例如 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的解决方案。我需要对两列进行排序。
提前致谢
最佳答案
您可以使用 '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
的短名称喜欢 ISO8601Long
, UniversalSortableDateTime
, ShortDate
等等(详见 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 代码中进行相应的更改。
关于sorting - jqgrid 日期排序和格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6476797/