Wednesday, 21 May 2014

Adding Conditional Style Sheet To Particular Row On Pageblock Table

Hi All,
This post is regarding for adding style sheet on a particular table row.
Here I am sharing some example where table row is yellow,if account Type is Prospect.

This is my page
<apex:page controller="conditionalStyleController">
    <apex:form >
        <apex:pageBlock title="Accoiunt Table">
            <apex:pageBlockTable value="{!listOfAccounts }" var="account">
                <apex:column value="{!account.Name}" style="{!if(account.Type='Prospect','background-color:yellow;', 'color:black')}"/>
                   
               
                <apex:column value="{!account.Type}" style="{!if(account.Type='Prospect','background-color:yellow;', 'color:black')}"/>
            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>
</apex:page>

My Controller
public with sharing class conditionalStyleController {
    public list<Account> listOfAccounts{get;set;}
    public conditionalStyleController(){
        listOfAccounts = [SELECT id,Name,Type FROM Account];
    }
}

Here is the image of result.

No comments: