Datatables jquery - alternate colors for strings

I used datatables jquery in my application. When I used datatables jquery to set alternate colors for my strings, I ran into a problem. That is, in the table, the 2nd, 3rd, 4th, 5th n 6th row are displayed in one color, after which the colors are displayed alternately. Can 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 attached a screenshot of the table.

enter image description here

When I checked, each line has either class = "even" or class = "odd", but 2, 3, 4, 5, 6 lines have class = "odd even". I do not know why this is so.

+4
source share
4 answers

Found answer:

 table.dataTable tr{ background-color: red; } table.dataTable tr:nth-child(even) { background-color: green; } 
+5
source

Try :odd and :even pseudo-seleders

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

In my application, I 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;} 

usually css and it works. Hope the same for your application.

+1
source

The following code should work. add these lines to datatable css file

 table.dataTable >tbody td { text-align: center; background: #99BCDB; } table.dataTable > tbody tr.odd td { background: #EBF2F8 ; } 
0
source

Source: https://habr.com/ru/post/1488045/


All Articles