primefaces datatable row coloring

You should have like two classes with different colors and use, in the rowStyleClass attribute, inline if:

rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'highlight1' : 'highlight2'}" 

Where "rowIndex" you should set in the datatable rowIndexVar attribute

rowIndexVar="rowIndex"

That means that even rows will have row style class set as 'highlight1' and odd rows - 'highlight2'

See here more info


Try this...It is working in my case

.ui-widget-content .ui-datatable-even{
    background: #F2F5F9;
}

.ui-widget-content .ui-datatable-odd{
    background: red;
}

The easiest way is to implement .ui-datatable-odd and .ui-datatable-even style classes in your CSS, which are implemented by p:dataTable by default. Example:

.ui-datatable-odd {
    background: #ffffff;
}

.ui-datatable-even {
    background: #F2F5F9;
}

Ends up looking something like

enter image description here

It could be you need to use more specific selectors, read about css specificity for that

Tags:

Primefaces