I need to have rows in a table alternate background color. I also need to have the text color in the rows be dependent on a value. How can I do this using Thymeleaf? Here's the code that I have:
<tr th:each="item, rowStat : ${items}"
th:style="${rowStat.odd} ? 'background: #f0f0f2;' : 'background: #ffffff;'"
th:style="${item.getValue()} > 5 ? 'color: red;' : 'color: black;'">
<td.... <!-- cols>
</tr>
This doesn't work though. Thymeleaf give a parsing error : Attribute "th:style" was already specified for element "tr".
Update
Meant to note that this an HTML email so I need to use inline styles.
Thymeleaf has a th:styleappend attribute that allows for multiple styles to be applied:
<tr th:each="item, rowStat : ${items}"
th:style="${rowStat.odd} ? 'background: #f0f0f2;' : 'background: #ffffff;'"
th:styleappend="${item.getValue()} > 5 ? 'color: red;' : 'color: black;'">
<td.... <!-- cols>
</tr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With