I have a table which is updated with ajax and after update it if sorted but I need to sort not a fixed column but the same column which was last clicked before update.
function tableUpdated() {
$(".tablesorter").trigger("update");
//alert($(".tablesorter").sorting);
var sorting = [[7, 0]];
$("table").trigger("sorton", [sorting]);
}
In my code above I need to put my selected column index instead of 7
jQuery’s
.data()will help you here. Whenever the user clicks to sort a table, store the columns on the table itself. Within the sort function, add this:Now the element with
id="table"has a propertysortingwith the value ofselectedColumn. In tableUpdated, you can use this data:Data added using
.data()can be even more complex, allowing you to add objects of data. See this page for more details.