I've got a bit of a problem with my table sorter sort at the moment. The issue is that I am sorting my time but when the column contains n/a I would like it to appear at the end of the sort. Can anyone help me achieve this please?
Here is my sort code...
$("#myStoreStatus").tablesorter({
sortList: [[2,1],[8,0],[0,0]],
stripingRowClass: ['even','odd'],
stripeRowsOnStartUp: true,
widthFixed: false,
widgets: ['zebra'],
dateFormat: "uk",
headers: {
0: { sorter: 'digit' } // column number, type
}
});
As far as I could understand the problem is that you want the n/a rows to appear always at the end, even if the sorting order for the time column is changed.
Here is one possible option.
$("#myStoreStatus").tablesorter({
sortList: [[2,1],[8,0],[0,0]],
stripingRowClass: ['even','odd'],
stripeRowsOnStartUp: true,
widthFixed: false,
widgets: ['zebra'],
dateFormat: "uk",
headers: {
0: { sorter: 'digit' } // column number, type
},
textExtraction: function (node) {
if (($(node).index()==8) && ($(node).text().toLowerCase()=='n/a'))
$(node).parent().addClass('jsnamark');
return $(node).text();
}
}).bind('sortEnd' function () {
$(this).append($(this).find('.jsnamark'));
});
Now, what this peace is doing is quite simple. It uses textExtraction function to check if the 8th (time) cell has the 'n/a' value. If it does then it adds a jsnamark class to its row. (you can also do the same thing in a several different ways with jQuery or from the server side if you are serving page with a server script).
When the sorting is done it reappends the rows that have the jsnamark class to the end of the table.