Jquery tablesorter for different date formats

In the jQuery table sorter doc http://tablesorter.com/docs/ we have a date on Jan 18, 2001 9:12 AM in this format.

If I change this date to the format January 12, 2010 , sorting does not happen.

Can anybody help?

+6
jquery jquery-plugins tablesorter
source share
1 answer

The Jquery tablesorter plugin understands the default usLongDate and shordDate Date format.

That's why he does not understand January 12, 2010 format.if you really want to use this format, then the right thing is to add your own parser for this custom format.

check the link to help you write your own parser .

In the tablesorter source, find the parser shortDate and usLongDate and try adding your own parser.

jquery.tablesorter.js

You can also try this, 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 to the tablesorter source and update the table in the browser, it will automatically identify the column and sorting will work. if it wont work, apply it to the column where you have this format, e.g.

 $(function() { $("table").tablesorter({ headers: { 4: { sorter:'customDate' } } }); }); 
+9
source share

All Articles