我无法找到使用动态数据更新表格的最佳方法。每次我切换到带有表格的页面时,同一个表都可以更改他的数据。
我尝试了$('#table').trigger('destroy')
,但后来我得到了“未捕获的类型错误:无法读取属性'删除'未定义'
我也试过
('#table').trigger('update')
和
var sorting = [[1, 0]];
// $('#table').trigger('sorton', [sorting]);
// setTimeout(function () {
// $('#table').trigger('sorton', [sorting]);
// }, 100);
似乎无法正常工作
我的代码: (表格准备好后)
$('#summary_table').tablesorter();
$('#summary_table').trigger('update');
var sorting = [[1, 0]];
setTimeout(function () {
$('#summary_table').trigger('sorton', [sorting]);
}, 100);
答案 0 :(得分:0)
要在使用tablesorter时在表格上设置初始排序,请设置sortList
option。
$(function(){
$('#summary_table').tablesorter({
sortList: [[1, 0]]
});
});
sortList
链接指向我fork of tablesorter上的文档,该文档与原始tablesorter(v2.0.5b)有很多不同,但此方法是相同的。
另外,只使用"更新"方法如果tbody的内容发生了变化。
要使表格对更新的数据进行重新排序,请使用update
method度假村变量:
// $("table").trigger("update", [resort, callback]);
// resort:
// [Boolean] true = resort using the already applied sort
// [Boolean] false = do not resort
// [Array] Array similar to how the sortList option is set -> apply new sort
$("table").trigger("update", [ [[1, 0]], function(){
// callback function called after update/sort completes
}] );