Changing font color of cell contents

Changing font color of cell contents

dbrendbren Posts: 3Questions: 1Answers: 0

Hello. I'm trying to change the font color of contents in cell. For example if cell contents of "ready" is <= 10 change color to red.

Code example-

$(document).ready(function() {
$('#demo').html( '

' );

table = $('#example').DataTable( {

retrieve: true,
paging: true,
stateSave: true,

    "data": dataSet,
    "columns": [
    { "title": "State" },
    { "title": "Ready" },
    { "title": "Not Ready", "class": "center" },
    { "title": "Busy", "class": "center" },
    { "title": "Logged Out", "class": "center" },
    { "title": "Total", "class": "center" }
    ]
} );   

} );

Thank you!!!

Answers

  • dbrendbren Posts: 3Questions: 1Answers: 0

    I saw this but dont know how to fit it into my code. Kind of a newb here.

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Add this to your datatables config.

     createdRow: function ( row, data, index ) {
                if ( data[2] < 10 ) {
                    $('td', row).eq(2).addClass('alert');
                }
            }
    

    You'll need to define a style in your css for

    .alert {
      background-color: red;
    }
    
    
  • dbrendbren Posts: 3Questions: 1Answers: 0

    I dont have a datatables config. That I know of..

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    I meant the in line options you defined when you invoke dataTables. Put it after your

    data: DataSet,
    
    
This discussion has been closed.