【问题标题】:DataTables - How do I get/set the value of a cell in a row?DataTables - 如何获取/设置连续单元格的值?
【发布时间】:2015-10-01 14:42:21
【问题描述】:

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

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

【问题讨论】:

    标签: get set datatables row cell


    【解决方案1】:

    解决方案

    您可以在匿名函数中使用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);
    });
    

    演示

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

    【讨论】:

    • 非常感谢……这么简单,还需要你指出来……来自秘鲁的问候
    【解决方案2】:

    您可以使用 rowID 来执行此操作;我们可以在rowCreated:Datatable的回调中设置rowID,或者在创建表时手动插入行。在这里,我在项目中的某些事件上增加了第三列的值。

    //DOM only addition
    var rowID = your rowID goes here; 
    
    var cols = Table.row(rowID).data();
    
    var count = parseInt(cols[2]);
    count = count + 1
    cols[2] = count.toString();
    Table.row(rowID).data(cols);
    

    【讨论】:

      猜你喜欢
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      相关资源
      最近更新 更多