Mottie/tablesorter

Sort on date not working

Closed this issue · 4 comments

kpym commented

I have column with dates like "31/01/2014" and tablesorter fails to sort on this column.
Here is an example :

http://jsfiddle.net/7Mp6z/1/

Sorting on "Arival date" gives random results.

Hi @kpym!

The dateFormat option needs to be changed to ddmmyyyy. Here is an updated demo.

$("#answerstable").tablesorter({
    dateFormat: 'ddmmyyyy',
    sortList: [[1,0]]
});
kpym commented

Thanks @Mottie ! I'm sorry to not reading the doc before writing an issue.
But it is still strange to me why with te default format we can find this random behavior.
Is a month bigger than 12 considered as 12 ? If so all dates in my example will be considered as same "12/06/2011" (December 6th, 2011).

The default is set up as "mmddyyyy" so the plugin sees 14/06/2011 and thinks the month is set to 14 which is an invalid date, so the shortDate parser tries to process that date, but it returns as invalid and then gets set as an empty string.

Empty strings can get sorted randomly since the natural sort algorithm is not a stable sort.

So, instead of setting it to an empty string, I will make the shortDate parser (and the other date parsers) return the original cell text. I'll include this change in my next update.

kpym commented

Ok. Thanks.