Saturday, 17 December 2011

Making the color for each cell in a pageblocktable based on condition


I am trying to show you how to change the colors of cells of pageBlockTable in visualforce based on condition
and also show you how to place the string literal in the cells based condition.

Here I have created an object with the name called Employeetest__c and having three fields are 


When the salary>=XXX and salary<XXX then make the color for that cell under the Salary column.
Like that for different conditions we need to set different colors for each cell based on condition.

and When status checkbox is checked then then place the "Active" in the cell  under the Status column otherwise 
place the "InActive" as string literals.


public class employeetestController{

    public List<Employeetest__c> lstemp=new List<Employeetest__c>();
    public List<Employeetest__c> getrecs(){
            lstemp=[select name,salary__c,status__c from Employeetest__c];
            return lstemp;


<apex:page controller="employeetestController"  sidebar="false">
<apex:form >
<apex:image value="{!$Resource.TestName}"/>
<apex:pageBlock >
<apex:pageblocktable value="{!recs}" var="e">
<apex:column value="{!}"/>
<apex:column >
<apex:facet name="header">Salary</apex:facet>
<div style="background-color:{!If(e.Salary__c>=7000 && e.Salary__c<10000,'#7CFC00',If(e.Salary__c>=10000 && e.Salary__c<100000,'#DEB887','#DC143C'))};width:30%;">
<apex:column >
<apex:facet name="header">Status</apex:facet>

VFpage with colors and string literals based oncondition

Try this all the best 

No comments:

Post a Comment

Get Record Type Id from lightning component in standard new action override (getting any url parameter)

Hi , Here we have requirement to get record type id from lightning component when standard "New" action is overrided. To get...