[SalesForce] Method to highlight a single row in an apex:dataTable

I have a dataTable as part of a Visualforce component, and I'd like to write some code to have it highlight a single row of the table, based on some value in that row's data.

Recall that an <apex:dataTable> contains multiple <apex:column> values, and it does not use an <apex:repeat> to loop through records. I would prefer to keep the dataTable for formatting reasons.

My current thought is whether I can include an <apex:outputPanel> that contains Javascript that can somehow find the parent <tr> of the current <td> and change its background-color.

Am I jumping through too many hoops? Will such a method even work, and what would it look like? Is there a simpler way to accomplish this?

My current workaround is an <apex:outputPanel> wrapping the text of a single cell, and setting the style to background-color:#FFFF00 or an empty string. It doesn't look good, and I'd prefer to highlight the entire row.

Best Answer

I am not sure if this is something you are looking for :

enter image description here

I used style per column based on a specific name to highlight a single row of the table, based on some value in that row's data (assuming row data from one column !!!)

<apex:page Controller="account_multicolor" >
<style>
.value{
background-color: #FCF7F7;}
</style>
<apex:dataTable value="{!account_val}" var="acc" rowclasses="">
<apex:column headervalue="Id" value="{!acc.Id}" style="{!IF((acc.name ='TEST'),"background-color: #0000FF;","")}"/>
<apex:column headervalue="name" value="{!acc.name}" style="{!IF((acc.name ='TEST'),"background-color: #0000FF;","")}"/>
</apex:dataTable>
</apex:page>