我使用FooTable 插件
初始化后我尝试
'on': {
'postinit.ft.table': function(e, ft) {
var
rows = table.rows.array;
for (var i = 0, l = rows.length, row; i < l; i++) {
row = rows[i].val();
total_sum += parseInt(row["sum_product"]);
total_count += parseInt(row["count_product"]);
}
var foot = $("#purchases_table").find('tfoot');
foot.prepend(
"<tr><th rowspan=\"1\" colspan=\"1\">SUMM</th><th rowspan=\"1\" colspan=\"3\"></th><th id='count_product_all' rowspan=\"1\" colspan=\"1\">" + total_count + "</th><th id='sum_product_all' rowspan=\"1\" colspan=\"1\">" + total_sum + "</th><th rowspan=\"1\" colspan=\"4\"></th></tr>\n");
},
一切都好 我需要改变这种动态
'draw.ft.table': function(e, ft) {
var rows = ft.rows.all;
total_sum = 0;
total_count = 0;
for (var i = 0, l = rows.length, row; i < l; i++) {
row = rows[i].val();
total_sum += parseInt(row["sum_product"]);
total_count += parseInt(row["count_product"]);
}
$("#count_product_all").html(total_count);
$("#sum_product_all").html(total_sum);
}
},
但是在html count_product_all
和sum_product_all
中只更改了1秒而又回到了0为什么?
答案 0 :(得分:0)
首先,你可以查看是否只在$(“#count_product_all”)输入一次.html(total_count);请。
像这样:'draw.ft.table': function(e, ft) {
var rows = ft.rows.all;
bool enter = false;
total_sum = 0;
total_count = 0;
for (var i = 0, l = rows.length, row; i < l; i++) {
row = rows[i].val();
total_sum += parseInt(row["sum_product"]);
total_count += parseInt(row["count_product"]);
enter = true;
}
if(enter){
$("#count_product_all").html(total_count);
$("#sum_product_all").html(total_sum);
enter = false;
}
}
},