Skip to content

Instantly share code, notes, and snippets.

@vivaserver
Created July 29, 2012 20:44
Show Gist options
  • Save vivaserver/3201752 to your computer and use it in GitHub Desktop.
Save vivaserver/3201752 to your computer and use it in GitHub Desktop.
DDMMYY date parser for TableSorter jQuery plugin
// DDMMYY date parser for TableSorter plugin
// 'cause stock "shortDate" sorter only works with 'yyyy' year format
// ref: http://tablesorter.com/docs/example-parsers.html
var regx = /(\d{2})\/(\d{2})\/(\d{2})/;
var match_dd_mm_yy;
$.tablesorter.addParser({
id: "ddmmyy",
is: function(s) {
return false;
},
format: function(s) {
match_dd_mm_yy = regx.exec(s);
// consider XX or XI century dates
return (match_dd_mm_yy[3]>="90" ? "19" : "20") + match_dd_mm_yy[3] + match_dd_mm_yy[2] + match_dd_mm_yy[1];
},
type: "numeric"
});
$(".domains").tablesorter({
headers: {
1: { sorter: "ddmmyy" },
2: { sorter: "ddmmyy" }
},
sortList: [[3,0]]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment