jqgrid date sorting and formatting

17,332

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.

Share:
17,332
Sabarish
Author by

Sabarish

user669789

Updated on June 25, 2022

Comments

  • Sabarish
    Sabarish almost 2 years

    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

  • Sabarish
    Sabarish almost 13 years
    thanx oleg, but sorting is not hapenning. my colmodel code is '{name:'invdate',index:'invdate',sorttype:'date', formatter:'date', formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/Y'} },' and my array data is '{id:"1",invdate:"2007-10-01",name:"test"}'. Do I miss any properties?
  • Oleg
    Oleg almost 13 years
    @user669789: Now I understand your main problem and suggest you to use srcformat:'Y-m-d H:i:s' instead of srcformat:'ISO8601Long' as a workaround. I updated my answer.