Datatables - How to change background color and cell text changed dynamically?

I use the following code to dynamically update the cell and perfect, the only thing that can be changed is the background color and text of the cell data. If this is a possible example of how to change the whole line. Thanks in advance.

$(document).ready(function (){
    var table = $('#example').DataTable();

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

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

        this.data(data);
    });
});
+4
source share
1 answer

DECISION

You can access the node cell using the cell().node()API method .

$(document).ready(function (){
    var table = $('#example').DataTable();

    table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
        var cell = table.cell({ row: rowIdx, column: 0 }).node();
        $(cell).addClass('warning');
    });
});

Demo

See this jsFiddle for code and demos.

+5
source

Source: https://habr.com/ru/post/1609845/


All Articles