2

I have a picklist called Status, displayed in a Visualforce table with fields like ..

  1. Closed
  2. Open
  3. Critical

      <div id="col1">
        <apex:column >
            <apex:facet name="header">Status</apex:facet>      
            <apex:outputText value="{!account.Status__c}"/>
        </apex:column>
      </div>
    

How can make all fields GREEN except the ones that are Critical RED? Thanks.

2 Answers 2

4

You can assign CSS classes dynamically based on the picklist value using styleClass attrubute:

<style>
.errorClass {
    background-color: red;
}
.normalClass {
    background-color: green;
}
</style>

<apex:pageBlock>
    <apex:pageBlockTable value="{!testObjectList}" var="item">
        <apex:column value="{!item.name}" 
                     styleClass="{!IF(item.status__c == 'Critical','errorClass','normalClass')}"/>
        <apex:column value="{!item.status__c}" 
                     styleClass="{!IF(item.status__c == 'Critical','errorClass','normalClass')}"/>
    </apex:pageBlockTable>
</apex:pageBlock>

The result page:

enter image description here

5
  • This is my controller... public class dataTableCon { List<Feedback__c> fb; public List<Feedback__c> getAccounts() { if(fb== null) fb= [select Name, Description__c, Importance__c, Resolution__c, Status__c,Owner.name from Feedback__c]; return fb; } } <br/>So in your code does testObjectList=fb in my code?
    – MnZ
    Commented Apr 16, 2014 at 12:06
  • @MnZ yes exactly Commented Apr 16, 2014 at 12:13
  • But it throws me this error .......Error: Unknown property 'dataTableCon.fb' Quick Fix Create Apex property 'dataTableCon.fb' Quick Fix Create Apex method 'dataTableCon.getFb'
    – MnZ
    Commented Apr 16, 2014 at 12:15
  • @MnZ You need to correct your own code by yourself. Commented Apr 16, 2014 at 12:19
  • 1
    I figured it out. <apex:column value="{!account.Status__c}" styleClass="{!IF(account.Status__c == 'Closed','errorClass','normalClass')}"/> <apex:column > This did the trick. I will update with an answer. Sorry to bother you.
    – MnZ
    Commented Apr 16, 2014 at 12:54
1

Only standard style sheets can be used in apex:pageBlockTable tag in Visualforce page. If we want to add custom style sheets we have to use apex:dataTable tag in Visualforce page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .