Conditional coloring in dataTable
The dataTable
component provides conditional coloring on rows, which can be styled based on conditions. The row styling utilizes the rowStyleClass
attribute that has a condition as the EL expression.
In this recipe, we will demonstrate the conditional coloring on rows for countries with GDP (gross domestic product) less than $3,500,000.
How to do it…
A basic definition of a color-coded table that displays a list of countries with their GDPs is given here:
<p:dataTable value="#{dataTableColoringBean.countryGdpList}" var="countryGdp" rowStyleClass="#{countryGdp.gdp le 3500000 ? 'colored' : ''}"> <p:column headerText="Name" sortBy="#{countryGdp.name}"> #{countryGdp.name} </p:column> <p:column headerText="GDP (Millions of US $)"> #{countryGdp.gdp} </p:column> </p:dataTable>
The colored style definition used in rowStyleClass...