I am trying to set up a VF page so that some of the columns only show when they have data. My VF page uses a custom list controller. I have tried using a rendered attribute in the column tag, and while that works when there is no data, if one of my rows has data the column header attribute remains blank. Does anyone know how I can accomplish this?

VF Page:

<apex:page Controller="CalculateQLISummary" action="{!init}" tabStyle="Quote__c">
    <apex:pageMessages id="pgMess" />

        <apex:pageBlock  title="Summary">
            <center><apex:commandButton title="Back" value="Back" action="{!cancel}"/></center><br/><br/>

        <apex:outputText value="Summary" /><p/>
            <apex:pageBlockTable title="Grouping Summary" value="{!listQLI2}" var="OLI2" style="width:100%">
                <facet name="Grouping"/>
                <apex:column headerValue="Product" style="width:30%">
                    <apex:outputField value="{!OLI2.Name}"/>
                <apex:column headerValue="List Price" rendered="{!IF(OLI2.List_Price__c != NULL,true,false)}">
                    <apex:outputField value="{!OLI2.List_Price__c}"/>
  • 1
    What data are you expecting to influence the rendering? Do you want to hide the column if no record in the collection has that column populated?
    – David Reed
    Commented Sep 10, 2018 at 17:41
  • Yes, that's exactly what I'm trying to do.
    – J. Neilan
    Commented Sep 10, 2018 at 17:45

1 Answer 1


Visualforce expressions don't support a syntax like what you seem to need:

<apex:column headerValue="List Price" rendered="{!ISFIELDPOPULATEDINANY(listQLI2, List_Price__c)}">
    <apex:outputField value="{!OLI2.List_Price__c}"/>

OLI2 here is your iteration variable, which will take on the value of each entry in listQLI2 as Visualforce renders the table. It can't act as a sort of proxy for the value of a field across the whole data set.

You have to drop to Apex to implement that summarization of the underlying list data. You could simply implement this as a Boolean property:

public Boolean anyListPricePopulated {
    get { 
        for (QuoteLineItem qli : listQLI2) {
            if (qli.ListPrice != null) {
                return true;
        return false;

Then, in Visualforce,

<apex:column headerValue="List Price" rendered="{! anyListPricePopulated  }">
    <apex:outputField value="{!OLI2.List_Price__c}"/>
  • That's a lot of extra code, but it definitely worked! Thanks
    – J. Neilan
    Commented Sep 10, 2018 at 19:11

You must log in to answer this question.

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