Search code examples
getsetdatatablesrowcell

DataTables - How do I get/set the value of a cell in a row?


I´m iterating through the rows of my DataTable with the example I found here in documentation but I want to get the data of the second column, analyze that value and then set my processed value on that cell.

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

Solution

  • SOLUTION

    You can use row().data() inside the anonymous function to get and set row's data. Please note that variable this in inside the anonymous function refers to row being iterated.

    var table = $('#example').DataTable();
    
    table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
        var data = this.data();        
    
        data[0] = '* ' + data[0];
    
        this.data(data);
    });
    

    DEMO

    See this jsFiddle for code and demonstration.