sethwb
11-10-2009, 06:05 PM
Goal: Implement jQuery Sort Table with custom date format: "10 October 2009"
Using: http://tablesorter.com/docs/ with jQuery latest
My attempt at altering the date parser (currently not working, but not throwing errors):
var monthNames = {};
monthNames["Januari"] = "01";
monthNames["Februari"] = "02";
monthNames["Maart"] = "03";
monthNames["April"] = "04";
monthNames["Mei"] = "05";
monthNames["Juni"] = "06";
monthNames["Juli"] = "07";
monthNames["Augustus"] = "08";
monthNames["September"] = "09";
monthNames["October"] = "10";
monthNames["November"] = "11";
monthNames["December"] = "12";
$.tablesorter.addParser({
id: 'datewithmonthname',
is: function(s) {
return false;
},
format: function(s) {
var hit = s.match(/^(\d{1,2})[ ](\w+)[ ](\d{4})$/);
//console.log(hit);
var m = hit[2];
m = monthNames[m];
var d = "0" + hit[1];
d = d.substr(d.length - 2);
var y = hit[3];
//console.log("" + y + m + d);
//alert("" + y + m + + d);
return "" + y + m + + d;
},
type: 'numeric'
});
$("#oldArticles").tablesorter({
headers: {
0: {
sorter:'datewithmonthname'
}
}
});
By default table sorter tries to sort my date field by the day (the first number it encounters).
Since I've updated the code it doesn't seem to follow any specific pattern, things just get jumbled around.
Please help!!!!
p.s.
I just want to add that the Month names are in Dutch and fully spelled out:
10 Augustus 2009
Using: http://tablesorter.com/docs/ with jQuery latest
My attempt at altering the date parser (currently not working, but not throwing errors):
var monthNames = {};
monthNames["Januari"] = "01";
monthNames["Februari"] = "02";
monthNames["Maart"] = "03";
monthNames["April"] = "04";
monthNames["Mei"] = "05";
monthNames["Juni"] = "06";
monthNames["Juli"] = "07";
monthNames["Augustus"] = "08";
monthNames["September"] = "09";
monthNames["October"] = "10";
monthNames["November"] = "11";
monthNames["December"] = "12";
$.tablesorter.addParser({
id: 'datewithmonthname',
is: function(s) {
return false;
},
format: function(s) {
var hit = s.match(/^(\d{1,2})[ ](\w+)[ ](\d{4})$/);
//console.log(hit);
var m = hit[2];
m = monthNames[m];
var d = "0" + hit[1];
d = d.substr(d.length - 2);
var y = hit[3];
//console.log("" + y + m + d);
//alert("" + y + m + + d);
return "" + y + m + + d;
},
type: 'numeric'
});
$("#oldArticles").tablesorter({
headers: {
0: {
sorter:'datewithmonthname'
}
}
});
By default table sorter tries to sort my date field by the day (the first number it encounters).
Since I've updated the code it doesn't seem to follow any specific pattern, things just get jumbled around.
Please help!!!!
p.s.
I just want to add that the Month names are in Dutch and fully spelled out:
10 Augustus 2009