jQuery tablesorter with row numbers
I am using the jQuery Tablesorter 2.0 plugin to provide some basic table sorting functionality.
On my table, I would like to ha开发者_C百科ve a column for row number. The trouble is, the Tablesorter plugin sorts this column with everything else. I have tried setting the "headers" attribute for the first column, but that only removes sorting capability. It does not prevent the column from being reordered when I sort by a different column.
Is having a list of row numbers possible with this plugin? Can you think of a way around the problem?
It sounds like you need to renumber the rows every time the table is sorted. Try this (use it after you have already initialized tableSorter on your table):
var table = $("#myTable");
table.bind("sortEnd",function() {
var i = 1;
table.find("tr:gt(0)").each(function(){
$(this).find("td:eq(0)").text(i);
i++;
});
});
I have found a solution about the ordenation of the ordinals numbers, based on @Chris Laplante code. The solution is run the sortEnd trigger just the first time, when the table is created. So i have to edit the source code. Have to take into account when updates the tablesorter software.
In file jquery.tablesorter.js around line 370, we can found the trigger:
// trigger sortend
setTimeout(function () {
$(table).trigger("sortEnd");
}, 0);
Change for:
// trigger sortend
if (runonce == undefined){
setTimeout(function () {
$(table).trigger("sortEnd");
}, 0);
runonce = true;
}
and define the variable runonce some place over the function appendToTable:
var runonce;
function appendToTable(table, cache) { ...
You can check the result on:http://formulaeweb.es/resultados.php clicking over "Puntos".
精彩评论