JQuery Tablesorter clear table information

I created a jquery table, which from time to time needs to be cleared, and re-populated, my clear method:

//Clear table content before repopulating values $('#table tr:gt(0)').remove(); 

Now I'm trying to use tablesorter to sort a specific column, but my problem is when I turn on tablesorter:

 //Initialize tablesorter $("table").tablesorter(); 

The table cleaning method no longer works, it simply adds new data with old data, creating a lot of duplicate information.

Please, help

+8
jquery tablesorter
source share
4 answers

To update tablesorter, you need to activate "update" before it updates its cache

 $('table').trigger('update'); 

You can also use the built-in function to clear the table.

 $.tablesorter.clearTableBody( table ); 

Here is the code combined from this demo

 var $table = $('table'); // use built in clear function $.tablesorter.clearTableBody( $table[0] ); $table .append('<tr><td>george</td><td>papard</td><td>68</td><td>19.99</td><td>55%</td><td>+3</td></tr>') .trigger('update'); 
+15
source share

I see no reason why this should not work. Does it work without the tablesorter plugin?

Why are you calling tablesorter() on table but trying to delete rows from #table ? Typo?

Try registering jQuery objects for $('#table') , $('#table tr') and $('#table tr:gt(0)') and see if everything is correct there.

+1
source share

The only way to make it work is to restore the entire table (delete it and create it again).

 $(".resultTablePlaceholder").html('').html('<table id="resultTable">...</table>'); $("#resultTable").tablesorter(); 
0
source share

Cause:

Because when we add some data to the table, it calls the buildCache () method and saves the table data in the cache variable, but when you delete data from the table, it is not going to make any changes to the cache variable.

when sorting data, than clearing the table and adding cached data to the table so that the data is also deleted.

Decision:

you can change the onselectstart () function or the mousedown event in tablesorter.js

 //here tb_35 = id of table cache = buildCache($('#tb_35')[0]); 
0
source share

All Articles