JQuery tablesorter plugin - sort updates after modified rows

I am using tablesorter 2.0 and I am updating the cell value with ajax. After the call, I will need to order the lines again, but the $ ('# thisTable') method. Trigger ('update') doesn't help me.

I do the markup inside the cells, but this may not be a problem.

$('#thisTable').tablesorter({ textExtraction: function(node) { return node.getElementsByTagName('input')[0].value; } }); 

Any help would be appreciated.

- Cree

+4
source share
4 answers

You can find the answer in the docs table sorter. You must raise another sorton event.

+3
source

This is my code.

 //append some content to the tbody $('table').trigger('update'); var $sort = $('table').get(0).config.sortList; $("table").trigger("sorton",[$sort]); 

The above is called after adding some rows to the table body. I can see the values ​​of $ sort, but the trigger function does not sort the newly added rows.

+1
source

I have a slight change in the source code. I added a parameter to the update event handler to ask for sorting.

$("#MyTable").trigger('update') will work as usual.

$("#MyTable").trigger('update', true) will request sorting after the update.

 $this.bind("update", function (e, sort) { var me = this; setTimeout(function () { // rebuild parsers. me.config.parsers = buildParserCache( me, $headers); // rebuild the cache map cache = buildCache(me); // ADDED if (sort) $(me).trigger('sorton', [me.config.sortList]); }, 1); }); 
+1
source

As for the implementation of the β€œupdate” event, it performs the update after a timeout of 1 ms. This function must be rewritten in a table sorter using a callback.

 $this.bind("update", function () { var me = this; setTimeout(function () { // rebuild parsers. me.config.parsers = buildParserCache( me, $headers); // rebuild the cache map cache = buildCache(me); }, 1); 
0
source

All Articles