DataTables - 如何获取/设置一行中的单元格的值?

rod*_*zun 3 get row set cell datatables

我正在使用我在文档中找到的示例遍历我的 DataTable 的行,但我想获取第二列的数据,分析该值,然后在该单元格上设置我的处理值。

tablaProgDetalle.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
 // I suppose here goes the processing and the setting of the cells values.
});
Run Code Online (Sandbox Code Playgroud)

Gyr*_*com 5

解决方案

您可以row().data()在匿名函数内部使用来获取和设置行的数据。请注意,this匿名函数内部的变量是指正在迭代的行。

var table = $('#example').DataTable();

table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
    var data = this.data();        

    data[0] = '* ' + data[0];

    this.data(data);
});
Run Code Online (Sandbox Code Playgroud)

演示

有关代码和演示,请参阅此 jsFiddle