Sorting by formatted date in jquery
1 answer
Check out the parser example page , it will show you how to create your own parser. You can play such dates with new Date(date)
or Date.parse(date)
. I don't have the means to test it, but something like this should work:
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'ddMMMyy',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// parse the string as a date and return it as a number
return +new Date(s);
},
// set type, either numeric or text
type: 'numeric'
});
All you have to do is specify the sorting method using a parameter headers
:
$(document).ready(function() {
$("dataTable").tablesorter({
headers: {
6: { // <-- replace 6 with the zero-based index of your column
sorter:'ddMMMyy'
}
}
});
});
+1
a source to share