Change color of a row in a striped table
Change color of a row in a striped table
Hi all!
I can't change the color of a row if the table is given the class "table-striped". I need that since the table is pretty long and it makes it much readable, problem is I need to mark some of the rows with a color. I tried with the rowCallback
"rowCallback": function( row, data, dataIndex){
if( stuff){
console.log(data)
$(row).addClass('newColoredClass');
}
},
The console log succesfully happen upon meeting the condition, and the class is correctly appended to the row. Thebackground-color: red;
I have given to newColoredClass does not show up. I realized the table-striped class overwrites it because upon removing it, the rows that are supposed to have a different background show up correctly.
Is there a workaround to this? Thanks!
This question has an accepted answers - jump to answer
Answers
Hi @sunbather ,
This is striping the table and colouring rows - is this what you're after?
Cheers,
Colin
Hello @colin ,
Thank you for your reply, I was wondering - to get the table striped I had to give it the class 'table-striped', how did you manage to obtain the same result without that? Is it that maybe I'm using an older datatables version? I unfortunately cannot change that.
Hi @sunbather ,
My table has
class="display"
defined, so it gets that default style. See this page here for the various options, and here for a few examples.Cheers,
Colin
Thank you!