Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primefaces datatable row coloring

Tags:

primefaces

I want to show datatable rows with different colors.

I am using rowStyleClass attribute. But It is not changing the colors

My code in datatable is,

rowStyleClass="highlight";

and my css file is looks like this,

.highlight {
    background: yellow  !important ;
}
like image 211
Ssv Avatar asked Mar 13 '13 11:03

Ssv


3 Answers

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

like image 183
Tudor Zgureanu Avatar answered Oct 16 '22 18:10

Tudor Zgureanu


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

like image 43
amphibient Avatar answered Oct 16 '22 19:10

amphibient


Try this...It is working in my case

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

.ui-widget-content .ui-datatable-odd{
    background: red;
}
like image 1
mrahman Avatar answered Oct 16 '22 19:10

mrahman