JQuery tablesorter with row numbers

I am using the jQuery Tablesorter 2.0 plugin to provide some basic table sorting functions.

In my table, I would like to have a column for the row number. The problem is that the Tablesorter plugin sorts this column with everything else. I tried to set the headers attribute for the first column, but that only removes the sorting options. This does not prevent reordering a column when I sort another column.

Does the list of line numbers in this plugin? Can you think about it?

+7
source share
2 answers

It looks like you need to renumber 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++; }); }); 
+12
source

I found a solution to ordering serial numbers based on @Chris Laplante code. The solution is launched by running sortEnd only the first time the table is created. Therefore, I need to edit the source code. Must be considered when upgrading tablesorter software.

In the jquery.tablesorter.js file around line 370, we can find the trigger:

 // trigger sortend setTimeout(function () { $(table).trigger("sortEnd"); }, 0); 

Edit for:

 // trigger sortend if (runonce == undefined){ setTimeout(function () { $(table).trigger("sortEnd"); }, 0); runonce = true; } 

and define the runonce variable in a specific place above the appendToTable function:

 var runonce; function appendToTable(table, cache) { ... 

You can check the result at: http://formulaeweb.es/resultados.php by clicking "Puntos".

0
source

All Articles