sorting dynamic tables with jquery and tablesorter
I have a page in an application where the user can move names from one column (table) to another.
I have a bunch of js that removes the selected row from table a and adds it to table b.
Everytime I change one of the tables I want to sort the tables.
The syntax is below, if only for my own reference as it took me ages to get it just right. I need to write a custom sorter as I need to sort on the second word (i.e. surname). But anyway, the following is in a function that gets called when a row is moved between tables…
function sort_table(table){
$(table).tablesorter();
$(table).trigger("update");
var sorting = [[0,0]];
// sort on the first column
$(table).trigger("sorton",[sorting]);
}
There’s nothing particularily novel here, all available around the net. The call to
$(table).trigger("update");
is there as I found that when I moved a row over to the right column and then sorted the left column the row appeared to be still in that table. This is because tablesorter uses a cache of some sort. Calling .trigger(“update”) forces it to rebuild the cache. Or something like that…
Did you ever end up making that custom sorter for surnames?