如何在动态表更新后刷新整个表排序缓存?
我正在使用JoeQuery的Stupid-Table jQuery插件来对一个简单的表进行排序。 我不知道如何在动态表上刷新整个排序缓存。
updateSortVal
函数允许更新单个单元格。 例如:
$age_td.updateSortVal(23);
但是当整个thead
和tbody
被替换时,如何刷新整个表?
这是我的代码:
$.ajax({ ... success: function(data) { $("#myTable thead, #myTable tbody").empty(); if (data.data.length > 0) { var $thead_tr; var $tbody_tr; for (var r = 0; r < data.data.length; r++) { if (r == 0) $thead_tr = $("").appendTo("#myTable thead"); $tbody_tr = $(" ").appendTo("#myTable tbody"); for (var c in data.data[r]) { if (r == 0) $("").html(c).appendTo($thead_tr); $(" ").html(data.data[r][c]).appendTo($tbody_tr); // I've tried adding `.updateSortVal(data.data[r][c]);` // to the above as well, but the cache for the `th` // needs to be re-cached as well, so let's do it all at once } } // I'd like to refresh the entire stupidtable cache here $("#myTable").stupidtable().show(); } } } });
也许你应该基本上删除你的表而不是清空它,然后重新创建它以重置合适的(例如,宽度replaceWith())
$("#myTable").replaceWith('
');
代替
$("#myTable thead, #myTable tbody").empty();
编辑
由于我不确定你所谓的缓存,我做了这个小提琴。 如果你重现你的问题,你能检查一下并解释一下吗?
小提琴演示在这里