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.

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
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
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;
}
}
});
} );
You can only call
$().DataTable()
with options once. See the manual for how to combine multiple options into a single initialisation call.Allan
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
If you link to the page showing the issue I would be happy to take a look at it.
Allan
Thank you Allan for all your help. I have it working now.