The table has a couple of columns including the first column containing custom Date format (dd-mm-yyyy HH:MM:SS)
e.g
<tr>
<td>14-05-2012 13:57:04</td>
<td>MTUPTTC01V4.3_E2E-LoadBalancer-1336992891.jtl</td>
<td>14-05-2012 13:10:03</td>
<td>14-05-2012 13:56:38</td>
<td>00:46:35</td>
<td>400</td>
<td>152328</td>
<td>2494</td>
<td>1.64%</td>
<td><a href="2012-05-14_13_56_52">Results</a></td>
</tr>
and i am using the following custom parser but it doesnt seem to work.
$.tablesorter.addParser({
id: 'jmeterDate',
is: function(s) {
return false;
},
format: function(s) {
var date = s.match(/^(\d{2})-(\d{2})-(\d{4})[ ](\d{2}):(\d{2}):(\d{2})$/);
var d = date[1];
var m = date[2];
var y = date[3];
var H = date[4];
var M = date[5];
var S = date[6];
var MS = 0;
//return '' + y + m + d;
return new Date(y, m, d, H, M, S, MS).getTime();
},
type: 'Numeric'
});
$("#tablesorter-table").tablesorter({
headers: {
0: {
sorter: 'jmeterDate'
}
}
});
See the following link for a complete example
I have solved the problem, it wasn’t the jQuery or the custom tablesorter, it was actually the Table content itself. length of some of the dates was not what was expected by the regex e.g
04-05-2012 13:7:1
Notice the 7 and the 1, the regex below expects atleast 2 digits.
s.match(/^(\d{2})-(\d{2})-(\d{4}) :(\d{2}):(\d{2})$/)
FIX:
s.match(/^(\d{1,2})-(\d{1,2})-(\d{4}) :(\d{1,2}):(\d{1,2})$/)
It now accepts digits with length of 1 or 2