jqgrid date sorting and formatting

2019-02-22 10:36发布

问题:

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'}

and

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

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.

Thanks in advance

回答1:

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'}

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.

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'.

The demo shows that such change will make local sorting works correct.

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.



回答2:

Many many thanks....I tried to bind jqgrid with remote data(json format) and I wanted to display the date format as dd/mm/yyyy. after using the below options

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

It's working perfectly.