How do I sort a date of format mm/yy with the jquery tablesorter?

I have a table wherein one of the columns displays the date in the mm/yy format viz. 12/08, 01/09, 02/08, etc.

How do I implementing sorting on this column with the jQuery tablesorter (http://tablesorter.com) so that the dates are appropriately sorted?

Using the default date format does not work as it expects a date of three elements (mm/dd/yy such as 01/06/09).

Add Comment
1 Answer(s)

See http://tablesorter.com/docs/example-parsers.html for information about custom parsers.

You need to do a text sort but with the year and month switched. You could use a format function similar to this:

format: function(s) {
    date = s.split(/\//);
    return date[1] + date[0];
},

There may be a simpler way, but that is what I was able to find in my quick search through the documentation.

Answered on July 11, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.