This question is similar to Is it possible to change table row colour if it contains a certain value in a gsp? but I couldn't quite get it to work with my scenario.
In my gsp table, I would like to change the row color to red if the status is equal to "DOWN". Here's what I have:
<g:each in="${compInstanceList}" status="i" var="compInstance">
<tr class="${array.contains(comp.status=="DOWN") ? 'highlightRed' : 'highlightGreen'}">
<td><g:link action="show" id="${compInstance.id}">${fieldValue(bean: compInstance, field: "name")}</g:link></td>
<td>${fieldValue(bean: compInstance, field: "status")}</td>
</tr>
</g:each>
Here's my css to change the color:
.highlightRed{
background-color: red;
}
.highlightGreen{
background-color: green;
}
I'm sure my problem is in the second gsp line shown. Thanks for your help.
Maybe is:
<tr class="${(compInstance.status=="DOWN") ? 'highlightRed' : 'highlightGreen'}">
instead of
<tr class="${array.contains(comp.status=="DOWN") ? 'highlightRed' : 'highlightGreen'}">