0

I have the following statement for an object, I'm trying to use highlighted columns in a pageBlockTable according to a specific value, this page gets the value of the field and set a background color.

The field has no default value, but when I save the record and check the code again, the value of the last 4 values sets to the text "Cerrada". Any ideas why is happening?

<apex:pageBlockSection title="Avance" >
    <apex:dataTable value="{!Recomendaciones__c}" var="RC" rowclasses="" align="center"  style="font-size:150%">
        <apex:column value="{!Recomendaciones__c.Avances__c}"
            style="{!IF(RC.Avances__c="Con avances significativos","background-color:#33FF33;",
        IF(RC.Avances__c="No hay avance","background-color:#00CCCC;",
        IF(RC.Avances__c="Avance mínimo","background-color:#FF6600;",
        IF(RC.Avances__c="Avance moderado","background-color:#FFCC33;",
        IF(RC.Avances__c="Cerrada","background-color:#FF0000;","")))))}"/>
    </apex:dataTable>
 </apex:pageblocksection>
3
  • Two questions: Does the color change apply to the entire column, or to individual cells of the table? Also, I don't think the IF statement is evaluating the way you want it to. Try something like style="background-color:{!IF(RC.Avances__c = "Text", '#7CFC00', '#FFA07A')}"
    – HomerJ
    Feb 17 '15 at 21:57
  • Thank you for your reply, it's a small table with only 2 cells, so I thought changing the color of the column would affect only the cell of the right. I tried to change the code to your suggestion, but this will set a color for any value different from the selected, with this statement. Could you please help me to set the other conditions or one more? Sorry for the inconvenience.
    – Robert
    Feb 17 '15 at 22:58
  • Do you rerender the portion after calling Save action?
    – unidha
    Mar 25 '15 at 1:20
1

Instead of using style If will recommend to use StyleClass attribute where you can define set of classes to change the look and feel. A Sample example:

<apex:column value="{!Recomendaciones__c.Avances__c}" 
styleClass="{!if(Record.Field__c == 'NULL' || Record.Field2__c == 'NULL','red',if(Record.Field__c != Record.Field2__c,'yellow',''))}" />

You can use same function with style attribute as well but there you have set in-line style instead of class name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.