Reputation: 13771
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?
Thanks in advance!
Upvotes: 1
Views: 17955
Reputation: 85598
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)
} )
Demo -> http://jsfiddle.net/qx84jw55/
Upvotes: 9