如何在动态表更新后刷新整个表排序缓存? [英] How can I refresh the entire table sorting cache after dynamic table update?
问题描述
我正在使用JoeQuery的愚蠢表 jQuery插件对一个简单的表进行排序。我不知道如何在动态表上刷新整个排序缓存。
updateSortVal
函数允许一个更新单个单元格。例如:
$ age_td.updateSortVal(23);
但是当整个 thead $时,如何刷新整个表格c $ c>和
tbody
被替换?
这是我的代码:
$。ajax({
...
成功:函数(数据){
$(#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 = $(< tr>)。appendTo(#myTable thead);
$ tbody_tr = $(< tr>)。appendTo(#myTable tbody);
for(var.d in data.data [r]){
if(r == 0 )$(< th>)。html(c).appendTo($ thead_tr);
$(< td>)。html(data.data [r] [c])。appendTo ($ tbody_tr);
//我试过添加`.updateSortVal(data.data [r] [c]);`
//上面也是如此,但是'th`
//的缓存也需要重新缓存,所以让我们一次性完成所有操作
}
}
//我想在这里刷新整个愚蠢的缓存
$(#myTable)。stupidtable()。show();
}
}
}
});
也许你基本上应该删除你的表而不是清空它,然后重新创建它以重置合适的(例如,宽度replaceWith())
$(#myTable)。replaceWith( '< table id =myTable>< thead>< / thead>< tbody>< / tbody>< / table>');
而不是
$(#myTable thead,#myTable tbody)。empty();
编辑
<由于我不确定你所谓的缓存,我做了这个小提琴。
如果你重现问题,可以检查并解释一下吗?
I'm using JoeQuery's Stupid-Table jQuery plugin to sort a simple table. I do not know how to refresh the entire sort cache on a dynamic table.
The updateSortVal
function allows one to update a single cell. For example:
$age_td.updateSortVal(23);
But how can I refresh the entire table when the entire thead
and tbody
is replaced?
Here's my code:
$.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 = $("<tr>").appendTo("#myTable thead");
$tbody_tr = $("<tr>").appendTo("#myTable tbody");
for (var c in data.data[r]) {
if (r == 0) $("<th>").html(c).appendTo($thead_tr);
$("<td>").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();
}
}
}
});
Maybe you should basically remove your table instead of emptying it, and then recreating it to reset suitable (width replaceWith() for example)
$("#myTable").replaceWith('<table id="myTable"><thead></thead><tbody></tbody></table>');
instead of
$("#myTable thead, #myTable tbody").empty();
EDIT
As I am not sure about what you call cache, I did this fiddle. Can you check it and explain me if you reproduce your problem ?
这篇关于如何在动态表更新后刷新整个表排序缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!