How to combine rowStyleClss and rowClasses in t:dataTable

432 Views Asked by At

I have three css style classes. Each of them set the background colour of a JSF datatable row. One would make the colour of the row orange (rowHighlight), the second would colour the row white (rowWhite) and the third would colour the row grey (rowGrey).

When a certain condition is met, I want the table row to be orange. If the condition is not met, I want the colour of the rows to alternate between white and grey using the other two style sheets. The end result should have rows coloured in orange, white and grey.

I read that rowStyleClass can achieve changing the colour of a row based on a certain condition. I read that rowClasses can achieve making rows alternate colours.

I tried:

rowStyleClass="#{holidayInfo.country == ‘France’ ? 'rowHighlight' : '’ }"
rowClasses="rowWhite,rowGrey"

But this resulted in all rows being white.

I also tried:

rowStyleClass="#{holidayInfo.country == ‘France’ ? 'rowHighlight' : 'rowWhite,rowGrey'}"

But this resulted in the row being coloured in orange when the condition was met whilst all other rows were white.

Does anyone know if it is possible to combine the two? I am new to JSF.

1

There are 1 best solutions below

0
Kayla Nelson On

I have managed to resolve the issue.

It looks like if you want to use rowClasses and rowStyleClass in the same datatable, the order of the attributes must be rowClasses first and rowStyleClass second.

I put rowStyleClass first and I had set the styleClass to be '' if the condition was not met. If this happened, rowClasses was ignored after setting the style class to ''. When I put rowClasses first, it was executed and the row colour alternated between white and grey . the atttibute rowStyleClass class was not ignored because the rows where the condition was met was coloured in orange.

Thank you to everyone who helped me work this out.