Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables - How do I change background and text color of a cell changed dynamically?

I use the following code to update a cell dynamically and works perfect, the only thing is how to change the color of the background and the text of that cell data. If it´s possible an example of how to change the entire row as well. 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);
    });
});
like image 335
rodzun Avatar asked Mar 15 '23 15:03

rodzun


1 Answers

SOLUTION

You can access the cell node by using 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 demonstration.

like image 94
Gyrocode.com Avatar answered Apr 06 '23 20:04

Gyrocode.com