I recently had trouble with the tablesorter.js where I couldnt sort by date because whitespace was breaking my script (tablesorter, wont sort by date correctly)
I finally figured this out and changed the code to the following
$.tablesorter.addParser({
id: 'dayMonthYear',
is: function (s) {
return false;
},
format: function (s) {
s = $.trim(s.replace(/\s+/g, ' '));
var date = s.match(/^(\d{1,2})[ ](\w{3})[ ](\d{4})$/);
var day = String(date[1]);
if (day.length == 1) {
day = "0" + day;
}
var month = monthNames[date[2]];
var year = date[3];
return sortableDate = '' + year + month + day;
},
type: 'numeric'
});
var monthNames = {};
monthNames["Jan"] = "01";
monthNames["Feb"] = "02";
monthNames["Mar"] = "03";
monthNames["Apr"] = "04";
monthNames["May"] = "05";
monthNames["Jun"] = "06";
monthNames["Jul"] = "07";
monthNames["Aug"] = "08";
monthNames["Sep"] = "09";
monthNames["Oct"] = "10";
monthNames["Nov"] = "11";
monthNames["Dec"] = "12";
This seemed to do the trick but i've just noticed that it doesn't work in IE8 or IE7. Seems to be fine in IE9.
Does older versions of IE have a problem with $.trim
? If so is there a work around?
Thanks
Edit: Think i may be getting closer to an answer, just found this http://www.javascripter.net/faq/trim.htm