jqgrid日期排序和格式化 [英] jqgrid date sorting and formatting
问题描述
我需要以mm / dd / yyyy和mm / dd / yyyy hh:mm:ss格式显示日期。我发现我们可以在colmodel中使用formatoptions
I need to display date in two formats like mm/dd/yyyy and mm/dd/yyyy hh:mm:ss. I found we can use formatoptions in colmodel
formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/y'}
和
formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/y h:i:s'}
但是我得到的输出在jqgrid为mm / dd / yy。任何一个给出解决方案如何显示mm / dd / yyyy。我需要为两列进行排序。
but i am getting output in jqgrid as mm/dd/yy. Shall any one give solution how to display mm/dd/yyyy. I need to do sorting for both columns.
提前感谢
推荐答案
p>您可以使用'Y'而不是'y'显示年份为'yyyy'而不是'yy':
You can use 'Y' instead of 'y' to display the year as 'yyyy' instead of 'yy':
formatter:'date', formatoptions: {srcformat:'ISO8601Long', newformat:'m/d/Y H:i:s'}
如果你想在mounth和tha da中没有前面的null(没有0 padding),你可以使用'n / j / Y'而不是'm / d / Y'。 'date'格式化程序支持的所有不同的可能标志可以在格式化程序的源代码。
If you want to have no preceding nulls (without 0 padding) in the mounth and tha da you can use 'n/j/Y' instead of 'm/d/Y'. All different possible flags supported by the 'date' formatter you can find in the source code of the formatter.
更新:问题是, srcformat的简称
喜欢 ISO8601Long
, UniversalSortableDateTime
, ShortDate
等等(请参阅文档了解详情)只能使用使用远程网格数据( datatype:'json'
或 datatype:xml
)。为了使本地排序工作正确,您应该使用 srcformat:'ISO8601Long'
至 srcformat:'Ymd H:i:s'
。
UPDATED: The problem is that the short names of the srcformat
like ISO8601Long
, UniversalSortableDateTime
, ShortDate
and so on (see the documentation for details) can be used only with the remote grid data (datatype:'json'
or datatype:xml
). To make local sorting work correct you should use instead of srcformat:'ISO8601Long'
to srcformat:'Y-m-d H:i:s'
.
我认为 srcformat
中的限制可能会被解释作为jqGrid中的错误。因此,我建议您在 trirand论坛中发布相应的错误报告。然后,Tony Tomov(jqGrid的开发人员)可以在jqGrid代码中进行相应的更改。
I think that the restriction in srcformat
could be interpret as a bug in jqGrid. So I recommend you to post the corresponding bug report in the trirand forum. Then Tony Tomov (the developer of jqGrid) could make the corresponding changes in the jqGrid code.
这篇关于jqgrid日期排序和格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!