4

I have used datatables jquery in my application. When I used datatables jquery to set alternate colors for my rows, I faced a issue. That is, in a table 2nd,3rd,4th,5th n 6th row are all displayed in same color and after that colors are displayed alternately. Could anyone help me with this? Thanks in advance.

My code in jquery.datatables.css :

table.dataTable tr.odd { background-color:  red; }
table.dataTable tr.even { background-color: green;  }

I have attached the screenshot of the table.

enter image description here

When I checked, every row is having either class="even" or class="odd" but the 2nd,3rd,4th,5th,6th rows are having class="odd even". I dont know why it is like this.

madth3
  • 7,275
  • 12
  • 50
  • 74
kishore
  • 1,587
  • 4
  • 15
  • 17

4 Answers4

5

Found the answer :

table.dataTable tr{ background-color:  red; }
table.dataTable tr:nth-child(even)  { background-color: green;  }
kishore
  • 1,587
  • 4
  • 15
  • 17
2

Try :odd and :even pseudo selecters

table.dataTable tr:odd { background-color:  red; }
table.dataTable tr:even { background-color: green;}
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
1

In my app I have used

#tableid >  thead >tr  {background: #0F0}   /* to color thead*/


table.dataTable tr.odd { background-color:  red; }   /* tr. not tr: */
table.dataTable tr.even { background-color: green;}

as a css rule and it works. Hope the same works for your application .

0

The following code should work . add those lines in datatable css file

table.dataTable >tbody td {
    text-align: center;
    background: #99BCDB;
}

table.dataTable > tbody tr.odd td { 
    background: #EBF2F8
;
}
Narasimma
  • 1
  • 1