1

I would like to conditionally render a column on my VF Page however does not appear to play nicely/support "rendered" logic. Any Help is appreciated!

<apex:column>     
    <apex:outputText value="{!a.Condition.ImpsHostedfromOutsideSource__c}" 
       rendered="{IF(!a.Condition.MRMFee__c == 'Visitor Data Hosting 
       Fees',true,false)}"></apex:outputText>
    <apex:inputField value="{!a.Condition.ImpsHostedfromOutsideSource__c}" 
       rendered="{!a.Condition.MRMFee__c == 'Visitor Data Hosting Fees'}">
    </apex:inputField>
</apex:column>

enter image description here

1 Answer 1

1

You can use the headerValue attribute of <apex:column> to display the column header.

Excerpt from the above mentioned documentation

headerValue

The text that should be displayed in the column header. If you specify a value for this attribute, you cannot use the column's header facet. Note also that specifying a value for this attribute overrides the default header label that appears if you use an inputField or outputField in the column body.

So your code would be

<apex:column headerValue="yourColumnName"> 
    <apex:outputText value="{!a.Condition.ImpsHostedfromOutsideSource__c}" rendered="{IF(!a.Condition.MRMFee__c == 'Visitor Data Hosting Fees',true,false)}"></apex:outputText> 
    <apex:inputField value="{!a.Condition.ImpsHostedfromOutsideSource__c}" rendered="{!a.Condition.MRMFee__c == 'Visitor Data Hosting Fees'}"> </apex:inputField> 
</apex:column>

And if you want the entire column to be rendered based on a condition then you can use the rendered attribute of <apex:column>

rendered

A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.

<apex:column headerValue="yourColumnName" rendered="false"> 
    <apex:outputText value="{!a.Condition.ImpsHostedfromOutsideSource__c}" rendered="{IF(!a.Condition.MRMFee__c == 'Visitor Data Hosting Fees',true,false)}"></apex:outputText> 
    <apex:inputField value="{!a.Condition.ImpsHostedfromOutsideSource__c}" rendered="{!a.Condition.MRMFee__c == 'Visitor Data Hosting Fees'}"> </apex:inputField> 
</apex:column>

I have added rendered="false" in the above mentioned code, you will have to replace it with your condition.

12
  • Okay thanks Vijay, however, I would like to only conditionally render the column name when these conditions are met. Is this possible? The dynamic render logic seems to work properly for the inputfield. Using your solution, the column name would be always present on the page.
    – FWSFDC
    Commented Sep 11, 2019 at 18:51
  • Yes you can, column also has rendered attribute which can be used. Updated the answer. Commented Sep 11, 2019 at 18:55
  • Vijay - I updated the code, however, now the column nor the inputfield is no longer displaying entirely. I think the rendered ="false" may have something to do with it. Appreciate your help.
    – FWSFDC
    Commented Sep 11, 2019 at 19:02
  • Yes rendered is used for that very reason, you will have to replace false with your condition. Commented Sep 11, 2019 at 19:11
  • No dice. I'm guessing there is some limitation in Salesforce that is preventing this.
    – FWSFDC
    Commented Sep 11, 2019 at 19:14

You must log in to answer this question.

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