In jQuery table sorter doc http://tablesorter.com/docs/ we have date in Jan 18, 2001 9:12 AM
this format.
If I am changing this date to January 12, 2010
format then sorting is not happening.
Can anyone please help?
Jquery tablesorter plugin understands usLongDate and shordDate Date formats by-default.
That's why it is not understanding January 12, 2010 format.if you really want to use this format then the right thing to do would be to add your own parser for this custom format.
check out the link to help you how to write custom parser.
In the tablesorter source, find out the shortDate and usLongDate format parser and try to add your custom parser too.
jquery.tablesorter.js
You can also try this one, it should work,
ts.addParser({
id: "customDate",
is: function(s) {
return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, [0-9]{4}|'?[0-9]{2}$/));
},
format: function(s) {
return $.tablesorter.formatFloat(new Date(s).getTime());
},
type: "numeric"
});
when you add it into your tablesorter source and refresh the table in the browser, it automatically identify the column and sorting will work. if it will not work then apply it to the column where you have this format, like
$(function() {
$("table").tablesorter({
headers: {
4: { sorter:'customDate' }
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With