问题
I am Using my project Tablesorter Plugin, I am Dynamic Added and Removed COLUMN and Rows, Also Delete Column and Rows,
Remove Column Rows And Add Rows Sortable Function Working Perfectly,
But Add New Column Dynamic Then Table Sorter Not Working.
Please Help how i solve This Problem.
I got The Following Error
**TypeError: h[list[i][0]] is undefined
h[list[i][0]].addClass(css[list[i][1]]);**
I Create Dynamic Column in Table, and I am Click The New Column Header.
回答1:
The original tablesorter (tablesorter.com) is will not work correctly if you add or remove columns, even if you trigger the "update" method. It is only designed to work with changes to the tbody.
You can use my fork of tablesorter to work properly in your case by triggering the "updateAll" method as follows:
var resort = true, // re-apply the current sort
callback = function(table){
alert('table updated!');
};
// let the plugin know that we made a update, then the plugin will
// automatically sort the table based on the header settings
$("table").trigger("updateAll", [ resort, callback ]);
Please note, the sortList option does update from its initial setting and always contains the current sort; but, it will not apply to the same column (it's a zero-based index) if a new column is inserted to the left of that sorted column.
来源:https://stackoverflow.com/questions/21678671/tablesorter-plugin-add-column-dynamic