Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqgrid date sorting and formatting

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

like image 534
Sabarish Avatar asked Jun 25 '11 08:06

Sabarish


1 Answers

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.

like image 122
Oleg Avatar answered Nov 13 '22 21:11

Oleg