I am using the jquery tablesorter plugin to sort a table. On of my the columns in my table shows the date in mm/yy format.
<tr>
<td class="col-name">...</td>
...
<td rel="2000" class="col-dob">10/00</td>
...
</tr>
<tr>
<td class="col-name">...</td>
...
<td rel="1986" class="col-dob">11/86</td>
...
</tr>
Note:
- Each cell has a unique class
- Date is displayed in the mm/yy format
- Cell with date receives the year as well
My jQuery code is as below:
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
// set a unique id
id: 'user-birthdate',
is: function(s) {
// return false so this parser is not auto detected
return false;
},
format: function(s) {
// format your data for normalization
var dateSplit = s.split('/');
if(2 !== dateSplit.length)
return 0;
return new Date(dateSplit[1], dateSplit[0], 1);
},
// set type, either numeric or text
type: 'numeric'
});
myClass.init = function() {
$('.module .user table').tablesorter({
sortList: [[0,0]],
widgets: ['zebra'],
headers: {
5: {
sorter:'user-birthdate'
}
}
});
}
myClass.init();
My problem is that the tableSorter interprets 00 as year 1900 instead of 2000 and hence the sorted data is not correct.
Any clue how can I resolve this? I am using jQuery 1.2.6 and the latest version of tablesorter.