Tablesorter feature patch (resort)
When adding a row to a table via JS or an ajax request, it is possible
to trigger a re-sort on a particular field but not on whatever fields
are currently selected by the user.
See http://tablesorter.com/docs/example-ajax.html for what I am
talking about. If, for example, you sort the table by last name and
add data to the table, you must specify what sorting method you want,
otherwise the data is added unsorted.
I ran into this problem as I wanted to replace the entire contents of
the table body with data from an ajax request, but maintain the users
currently selected sort order.
I've added a 'resort' trigger (patch below against svn release 3798 /
plugins/tablesorter/2.0/jquery.tablesorter.js) that is close in
functionality to the current 'sorton' trigger.
611,615d610
<
< }).bind("resort",function(e) {
<
< // update and store the sortlist
< var sortList = config.sortList;
617,625d611
< // update header count index
< updateHeaderSortCount(this,sortList);
<
< //set css for headers
< setHeadersCss(this,$headers,sortList,sortCSS);
<
< // sort the table and append it to the dom
< appendToTable(this,multisort(this,sortList,cache));
<
Using the above patch, I am able to add/replace the table contents and
resort them using the currently selected sorting method using a
command similar to:
$("#sortedtable tbody").html(some_html);
$
("#sortedtable").trigger("update").trigger("resort").trigger("applyWidgets");