1

I need to change the color of the row in the table to red if the school.student_to_teacher_ratio__c is less than 5 or else the default color should be green. How do I do that?

<apex:outputPanel id="school">
<apex:pageblock title="School Details">
  <apex:pageblockTable value="{!slist}" var="school">
       <apex:column value="{!school.name}" headerValue="School Name"/>

       <apex:column value="{!school.No_of_Students__c}" headerValue="No of Students"/>

       <apex:column value="{!school.No_of_Teachers__c}" headerValue="No of Teachers"/>

       <apex:column value="{!school.Student_to_Teacher_ratio__c }" headerValue="Student to Teacher ratio"/>

    </apex:pageblockTable>
</apex:pageblock>
</apex:outputPanel>
2
  • 5
    Welcome to SFSE. I think this link will be useful for you. Change Cell Colors.
    – manjit5190
    Oct 21, 2015 at 12:09
  • The code in that link is giving me an error. The answer by Ashwani solved my problem partially as it changed only the color of the cell but not the entire row
    – User2529
    Oct 21, 2015 at 12:25

1 Answer 1

3

You can use style attribute for the column cell as:

<apex:column value="{!school.Student_to_Teacher_ratio__c }" 
        headerValue="Student to Teacher ratio"
        style="{!IF(school.Student_to_Teacher_ratio__c>70,'background-color:green;',background-color:red;')}"/>

style applied on column tag always applied to its cell not header.

6
  • Any way how I can change the color of the entire row?
    – User2529
    Oct 21, 2015 at 12:23
  • @User2529 apply same condition for each column.
    – Ashwani
    Oct 21, 2015 at 12:33
  • The color of individual cells in each row is getting changed. Can I not just change the color of the entire row as a whole?
    – User2529
    Oct 21, 2015 at 12:48
  • You cannot directly access rows
    – Ashwani
    Oct 21, 2015 at 12:50
  • Okay, I'm sorry I'll rephrase. Only the color of values in the cells are getting changed but not the entire cell itself. What do I do?
    – User2529
    Oct 21, 2015 at 12:54

You must log in to answer this question.

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