Reputation: 114
I have an issue when sorting dates using jqGrid
. Given the following dates
jqGrid
is sorting my dates as follows
01/01/2010
01/01/2011
01/02/2010
01/02/2011
I would expect to see
01/01/2010
01/02/2010
01/01/2011
01/02/2011
The column is described as follows:
{name:'F_ALTA',index:'F_ALTA',width:60,align:'right'},
Seeing lots of answers about this, pero all the answers doesnt work for one reason, the date is completely changed. I mean, if I define the column like this:
{name:'F_ALTA',index:'F_ALTA',width:60,align:'right',formatter:'date', formatoptions: {newformat:'m/d/Y'}, datefmt: 'd-M-Y'},
The date 17/11/2014
is converted to 05/07/2023
or the date 26/03/2015
is converted to 09/05/2031
.
So that's my problem :P Anybody can give a clue??
Thanks in advance.
Upvotes: 1
Views: 35
Reputation: 74738
Try with this:
{
name:'F_ALTA',
index:'F_ALTA',
width:60,
align:'right',
sorttype:'date',
formatter:'date',
formatoptions: {srcformat: 'd/m/Y', newformat:'m/d/Y'}
}
There is no need for datefmt: 'd-M-Y'
and formtoptions should be an object with two options srcformat
which is current date format and newformat
as the name suggests new output format for dates.
and i guess you need to have sorttype:'date'
also.
Upvotes: 1