Mirage LIVE PREVIEW

DataTable - Color

Certain rows can be styled based on a condition using rowStyleClass. Table below highlights cars that are manufactured before 1990.

Documentation
IdYearBrandColor
806ff9d51963VolvoRed
c8457b961988MercedesSilver
606970d11983RenaultYellow
f3528fa61999HondaBrown
8b2bdf511960VolkswagenOrange
3b179b6e1992BMWOrange
cde42dac1964FiatRed
1abbec0f1967FiatOrange
4b7e2cea1964MercedesSilver
4111c7c61975VolkswagenGreen
<style type="text/css">
    .old {
        background-color: #fca752 !important;
        background-image: none !important;
        color: #000000 !important;
    }
</style>

<p:dataTable var="car" value="#{dtBasicView.cars}" rowStyleClass="#{car.year le 1990 ? 'old' : null}">
    <p:column headerText="Id">
        <h:outputText value="#{car.id}" />
    </p:column>

    <p:column headerText="Year">
        <h:outputText value="#{car.year}" />
    </p:column>

    <p:column headerText="Brand">
        <h:outputText value="#{car.brand}" />
    </p:column>

    <p:column headerText="Color">
        <h:outputText value="#{car.color}" />
    </p:column>
</p:dataTable>