Created
February 17, 2017 09:28
-
-
Save spresnac/2172fd336c596f0d4c4d8e223645ca99 to your computer and use it in GitHub Desktop.
js-tablesorter: Handle german date format to sort correctly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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