I want to sort a date column with the JQuery Tablesorter Plugin. I have created my custom parser as my date is not in 'dd/mm/yyyy' format or other accepted formats.
$.tablesorter.addParser({
id: 'dayMonthYear',
is: function (s) {
return false;
},
format: function (s) {
let date = s.match(/^(\d{1,2})\s+(\w+)\s+(\d{4})$/);
let d = date ? date[1] || '' : '';
let y = date && date[3] ? date[3] || '' : '';
let m = date && date[2] ? date[2] || '' : '';
return new Date(d + " " + m + " " + y).getTime() || '';
},
type: 'Numeric'
});
$('#leaderBoardTable').tablesorter({
theme: "default",
headers: {1: {sorter: 'dayMonthYear'}} //add the custom parser we defined above
});
However, our system has multiple translations: NL, FR, JA, RU, ES and 21+ more. This parser only worked for the EN translation. Therefore this parser did not work for the other translations:
1 July 2020 (EN) //works
20 juli 2020 (NL) //doesn't work
Here is a fiddle showing my problem. http://jsfiddle.net/jLuzqp7r/4/
The bottom table sorts perfectly, while the top doesn't.