function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
benwrigleybenwrigley 

Changing styles of rows in pageBlockTable based on cell values

Hi There,

 

I'm sure this is much easier than I think it is.

 

I am using pageBlockTable to display a list of Products.

 

I want to be able to make the whole row grey if Product.IsActive == false.

 

Is there an easy way?

 

TIA

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Hello Ben,

  try this.

 

<apex:pageblocktable var="item" value="{!Opportunity.OpportunityLineItems}">
   <apex:column style="{!IF(NOT(v.isActive__c), 'background-color:grey', '')}"                                                 value="{!v.unitPrice}"/>  
</apex:pageblocktable>

All Answers

prageethprageeth

Hello Ben,

  try this.

 

<apex:pageblocktable var="item" value="{!Opportunity.OpportunityLineItems}">
   <apex:column style="{!IF(NOT(v.isActive__c), 'background-color:grey', '')}"                                                 value="{!v.unitPrice}"/>  
</apex:pageblocktable>
This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

You can use 'rowclasses' attribute in pageblocktable to customize your css and put css in Visual force page like the sample code given below:

 

.changecss

{

background-color:#00ff00;

}

<apex:pageblocktable rowClasses="changecss" value={!listproduct}>

 

Hope this helps.

benwrigleybenwrigley

This works a treat. I hadn't realised we could embed APEX in a VF page.

 

Thanks

craigmhcraigmh

when I tried this, it only made the one cell gray. this makes sense, since it applies only to the apex column. is there a way to get the entire row to turn gray?

matsonjmatsonj

 

craigmh wrote:

when I tried this, it only made the one cell gray. this makes sense, since it applies only to the apex column. is there a way to get the entire row to turn gray?


Yes. You apply the same formatting to each column.

craigmhcraigmh

Yeah, that's what I ended up doing. Made me twitch to do copy/paste programming, but oh well. A limitation of the platform.

ErashadErashad

Craigmh,

 

One more efficient way of doing this is by using your own table and displaying data using <apex:repeat>

See below(line 3):-

Using this method is more efficient in terms of execution, but you have to define your own table and style.

It is cumbersome to write, but more efficient..

 

<table>
         <tr ><th>Subscriber_Name</th><th>Customer Name</th></tr>
         <apex:repeat value="{!Opportunity.Subscribers__r}" var="subs2">         
         <tr class={!IF(subs2.Name!=someVar,'red','green')}>
         <td><apex:outputText value="{!subs2.Name}"/></td>
         <td><apex:outputText value="{!subs2.Contact__r.FirstName}"/>&nbsp;<apex:outputText value="  {!subs2.Contact__r.LastName}"/></td>
         </tr>
         </apex:repeat>
         </table>