tablesorter插件添加列动态

时间:2014-02-10 13:34:07

标签: tablesorter

我正在使用我的项目 Tablesorter插件,我是动态添加和删除的列和行,还删除列和行,

删除列行并添加行可排序函数完美运行,

但添加新列动态然后表格分类工具无效。

请帮助我解决这个问题。

我收到了以下错误

**TypeError: h[list[i][0]] is undefined 

h[list[i][0]].addClass(css[list[i][1]]);**

我在表中创建动态列,然后单击“新列标题”。

1 个答案:

答案 0 :(得分:1)

如果添加或删除列,原始tablesorter(tablesorter.com)将无法正常工作,即使您触发“更新”方法也是如此。它仅用于处理tbody的更改。

您可以通过触发fork of tablesorter按照以下方式使用我的"updateAll" method在您的情况下正常工作:

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 ]);

请注意,sortList option会从其初始设置更新并始终包含当前排序;但是,如果在该排序列的左侧插入一个新列,它将不会应用于同一列(它是一个从零开始的索引)。