JQgrid sort by date that is sent as string by server
My server is sending a date to javascript as string in format of
"csd":"08-SEP-2015"
I want to sort the data by date on this column. But the sorting doesnt works.
here is my colModel
{
name: 'csd',
index: 'csd',
width: 110,
align: 'left',
sorttype: 'date',
datefmt:'d-M-Y'
}
Update1:
I am using jqGrid 4.5.4 - jQuery Grid
Added note: I dont want to format the date, i just want the column to be sortable as date.
Update2:
I updated the definition as
{
name: 'csd',
index: 'csd',
width: 110,
align: 'left',
sorttype: 'date',
formatter:'date',
formatoptions:{srcformat:'d-M-Y' , newformat:'d-M-Y'}
}
but now I am getting NaN-undefined
in the field.
Marking the question for close,Answer found at:
JQgrid Sorting date on the client side with a specific format
It's bad to use language specific format for transferring the data. The format dMY
is locale dependent. I'm not PHP developer, but see that PHP have setlocale() and Date/Time Functions should depend on the locale. In the same way the format dMY
used by formatter: "date"
is also locale dependent and you will have different results depend on the locale which you use (try grid.locale-de.js
, grid.locale-ru.js
, grid.locale-jp.js
ans so on).
I would recommend you to use ISO 8601 format: which will display 08-SEP-2015 as 2015-09-08 in the simplest case.
链接地址: http://www.djcxy.com/p/25962.html