I am very new to this. I need to get cell to be certain by their value. here is my code.

I am very new to this. I need to get cell to be certain by their value. here is my code.

tommytidwell14tommytidwell14 Posts: 4Questions: 1Answers: 0

function stationCellColor () {
$('#basic-table').dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
switch(aData[2]){
case '1':
$(nRow).css('color', 'red')
break;
case '2':
$(nRow).css('color', 'green')
break;
case '3':
$(nRow).css('color', 'blue')
break;
case '4':
$(nRow).css('color', 'orange')
break;
case '5':
$(nRow).css('color', 'white')
break;
}
}
});
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,136Questions: 1Answers: 10,584 Site admin

    Could you post your question in the message body please? I don't actually know what your question is. Please also link to a page showing the issue, per the forum rules.

    Allan

  • tommytidwell14tommytidwell14 Posts: 4Questions: 1Answers: 0

    i need to get some cells to change color depending on their value. when i try to run the code i get this error. (datatable warning: table id=basic-table-cannot reinitialize datatable)
    how can i get this code to run without reinitialize the table. or if you can point me in the right direction to get my datatable to change certain cells depending on their value. thank you.

    // change cell color by value
    $(document).ready(function() {
    $('#basic-table').dataTable({
    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
    switch(aData[3]){
    case '1':
    $(nRow).css('color', 'red')
    break;
    case '2':
    $(nRow).css('color', 'green')
    break;
    case '3':
    $(nRow).css('color', 'blue')
    break;
    case '4':
    $(nRow).css('color', 'orange')
    break;
    case '5':
    $(nRow).css('color', 'white')
    break;
    }
    }
    });

    } );

  • allanallan Posts: 64,136Questions: 1Answers: 10,584 Site admin

    You can only call $().DataTable() with options once. See the manual for how to combine multiple options into a single initialisation call.

    Allan

  • tommytidwell14tommytidwell14 Posts: 4Questions: 1Answers: 0

    okay i see where i have to put the fnCallBack now, but my code still doesnt change the cell according to the cell value.
    thank you for your help

  • allanallan Posts: 64,136Questions: 1Answers: 10,584 Site admin
    Answer ✓

    If you link to the page showing the issue I would be happy to take a look at it.

    Allan

  • tommytidwell14tommytidwell14 Posts: 4Questions: 1Answers: 0

    Thank you Allan for all your help. I have it working now.

This discussion has been closed.