Skip to content

Instantly share code, notes, and snippets.

@spresnac
Created February 17, 2017 09:28
Show Gist options
  • Save spresnac/2172fd336c596f0d4c4d8e223645ca99 to your computer and use it in GitHub Desktop.
Save spresnac/2172fd336c596f0d4c4d8e223645ca99 to your computer and use it in GitHub Desktop.
js-tablesorter: Handle german date format to sort correctly
$.tablesorter.addParser({
id: 'germanDate',
is: function(s) {
return false;
},
format: function(s) {
var dateMatches = s.match(/([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{2,4}) ([0-9]{1,2}):([0-9]{1,2})/i);
return dateMatches[3]+dateMatches[2]+dateMatches[1]+dateMatches[4]+dateMatches[5];
},
// set type, either numeric or text
type: 'numeric'
});
$('#tblApps').tablesorter({
sortList: [[1,0]],
headers: {
0: { sorter: false },
2: { sorter: 'germanDate' },
3: { sorter: false }
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment