Change colors of multiple cells in row
Change colors of multiple cells in row
johnbel
Posts: 2Questions: 1Answers: 0
I am trying to change colors of multiple cells on a row. Right now only the second target gets changed. What do I need to do differently to get results for both cells? Is there a better method to achieve what I'm trying to do?
columnDefs: [
{
targets: 9,
createdCell: function (td, cellData, rowData, row, col) {
switch ( cellData) {
case "Offline":
$(td).css('color', 'red')
break;
case "Decomm":
$(td).css('color', 'blue')
break;
case "Online":
$(td).css('color', 'green')
break;
case "BeingBuilt":
$(td).css('background', 'yellow')
break;
case "PoweredOff":
$(td).css('color', 'red')
break;
}
},
targets: 10,
createdCell: function (td, cellData, rowData, row, col) {
var t = parseInt(cellData);
if ( t > 180) { $(td).css('background', 'red');} else
if ( t > 150) { $(td).css('background', 'yellow');}
}
}]
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Your array of
columnDefs
contains only one object. So lines 23-28 are overwriting lines 3-22. I made a test case for you to show what you need to change:http://live.datatables.net/woxozeya/1/edit
I updated the
columnDefs
array to contain two objects.Kevin
Of course, makes perfect sense. Thank you!