我使用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,为什么呢?

发布于 2018-04-07 00:08:57
首先,请检查是否只在$(“#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;
}
}
},https://stackoverflow.com/questions/49694247
复制相似问题