function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Get value from controller for every row of dataTable

I would like to apply different formatting for a column in a dataTable based on the value of one of the fields in the current record that the dataTable is displaying.  Basically, I need to color-code the 'rows' of the data table based on the value of one of the fields. 

I am currently doing this in the apex markup with an ugly, redundant set of 'IF' statments in the 'styleClass' attribute :

<apex:column headerValue="Description" style="text-align:left" width="20%" styleClass="{!if(Record.Investment_Status__c ='Exited', 'data1',if(Record.Investment_Status__c ='Portfolio Company', 'data2',if(Record.Investment_Status__c ='Signed Term Sheet', 'data3',if(Record.Investment_Status__c ='Terms Proposed', 'data4', if(Record.Investment_Status__c ='Due Dilligence', 'data5',if(Record.Investment_Status__c ='Visit- Multiple', 'data6',if(Record.Investment_Status__c ='Visit - Once', 'data7',if(Record.Investment_Status__c ='For Discussion', 'data8',if(Record.Investment_Status__c ='Conference Call', 'data9','color:black') ))))))))}">
     <apex:outputText value="{!Record.Description}"/>

Ideally, I would like to create a method back in the controller which can return the proper styleClass value for each column.  I can't seem to figure out how to pass these values back and forth while the dataTable is getting setup.    Do I have to do some commandLink parameter passing and basically 're-render' each column with a roundtrip to the controller?    Am I missing the simple way to do this?? 


Mark YoungMark Young

Add a class wrapper around your SObject so that the dataTable is binding to an array of WrapperObjects.

This wrapper can then expose a StyleClass property as a function of it's child SObject which you can use.

Hi Mark,

Thanks for the note.  I think I see what you are saying.  I'll give this  a shot and see how it works.


thanks for the insight.  with your comments, and the excellent post from Ron Hess here:

I was able to do just exactly what I needed.

Mark YoungMark Young

No worries,

Although I would love to see this ability in the future where we could bind to a method with parameters - i.e.

<apex:outputText value="{!CssStyle(Record.Investment_Status__c)}" />


could not agree more.  thanks again for the help.