如何更新数据表列中的数据 [英] How to update data in datatable column

查看:84
本文介绍了如何更新数据表列中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我遍历datatable列中的所有行并更新其中的数据吗?到目前为止,我已经找到了一种遍历一列的方法:

Can someone help me loop through all the rows in a datatable column and update the data in it? So far I've found a way to loop through a column:

var table = $("#my_table").DataTable();
table.column(2)
    .data()
    .each(function(value, index) {
        console.log(value);
        value = 'abc123'; //this does not work
    });

但是,我不确定如何更新该值.有人可以帮忙吗?

However, I'm not sure how to update that value.. Can someone help?

提前谢谢!

推荐答案

column返回整个表的汇总数据.而是遍历行.有一个 every() 辅助函数让生活更轻松:

column returns aggregated data for the entire table. Loop through rows instead. There is a every() helper function that makes life easier :

table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
   var data = this.data();
   data[2] += ' >> updated in loop' //append a string to every col #2
   this.data(data)
} )

演示-> http://jsfiddle.net/qx84jw55/

Demo -> http://jsfiddle.net/qx84jw55/

这篇关于如何更新数据表列中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆