The German date format is 01.05.2015
as opposed to the UK date format 01/05/2015
which Tablesorter.js comes prebuilt to parse.
To sort by a German date, you have to add a custom parser. Here is one that will work for a date with the German dot notation.
$.tablesorter.addParser({
id: 'dotDate',
is: function (content) {
return /\d{1,2}\.\d{1,2}\.\d{1,4}/.test(content);
},
format: function (content) {
content = content.replace(/\-/|:|\.|\//g,' ').split(' ');
return $.tablesorter.formatFloat(new Date(content[2], content[1]-1, content[0]).getTime());
},
type: 'numeric'
});
Simply add this parser and then tell your tablesorter
initializer function which column the German date is in.
$('table').tablesorter({
headers: {
0: { sorter: 'dotDate' }
}
});
If your date only has 2 numbers for the year instead of 4, you can adjust the is
method to use the regex /\d{1,2}\.\d{1,2}\.\d{1,2}/
.