user1905861
user1905861

Reputation: 9

Jqgrid Datetime format sorting issue

I have a datetime format returned from the backend(dd/MM/yyyy HH:mm:ss).

JQgrid has column values as {name:'createddate',index'createddate',sorttype:'date',formatter:'date'}

but the sorting is not working properly

the result is displayed as follows:for example

06/11/2013 01:23:33

11/09/2013 02:22:34

20/09/2013 01 22:33

but the result required is:

11/09/2013 02:22:34

20/09/2013 01:22:33

06/11/2013 01:23:33

Thanks in advance.

Upvotes: 0

Views: 3102

Answers (1)

Oleg
Oleg

Reputation: 221997

If you use formatter:'date' then you should specify formatoptions with srcformat and newformat options. Default format of input data (srcformat) which expect formatter:'date' is ISO8601Short: "Y-m-d". You use another format so you have to specify srcformat. Format of date which uses jqGrid is PHP format (described here). So I think that the problem will be solved by adding

formatoptions: {srcformat: "d/m/Y H:i:s", newformat: "d/m/Y H:i:s"}

More better would be to use ISO-8601 format if you returns data from the server. It's locale independent format. You can use on the server side DateTime.ToString("o") or DateTime.UtcNow.ToString("o"). In the case you can change formatoptions to

formatoptions: {srcformat: "ISO8601Long", newformat: "d/m/Y H:i:s"}

Upvotes: 3

Related Questions