+ Start a Discussion
Hugo StoupeHugo Stoupe 

Using "IF" Statement to evaluate a apex:column field value to decide whether or not to display

Is it possible to use and IF statement when displaying date from a LIST using apex:column.  In my example below, I want to check the value of Monday_Date and if it is in a specific month, display the "Monday" field; if not, then don't display the "Monday" field.

In my Data set, there is a field called "tec.Monday_Date__c" which I don't display on the page.  I would like to check the value of the "tec.Monday_Date__c" and if it equals a certain month, then display the data in the "tec.Monday__c" field; if not, then display nothing.

In psuedo-code, I would like to do this:

If (MONTH(tec.Monday_Date__c) = MONTH(tec_Start_date__c),
   Then   <apex:column width="10" value="{!tec.Monday__c}"/>
    Else   don't display the value for that column.

Is that possible?

 
<apex:pageBlockSection title="Billable Docket Report" columns="1" collapsible="False">Test
                <apex:pageBlockTable value="{!TEList}" var="tec">
                    <apex:column width="30" value="{!tec.Functional_Area__c}"/>
                    <apex:column width="20" value="{!tec.Standard_Activities__c}"/>
                    <apex:column value="{!tec.Activity_Other__c}"/>
                    <apex:column width="10" value="{!tec.Project__c}"/>
                    <apex:column width="10" value="{!tec.Contract__c}"/>
                    <apex:column width="10" value="{!tec.Monday__c}"/>
                    <apex:column width="10" value="{!tec.Tuesday__c}"/>

 
Best Answer chosen by Hugo Stoupe
KevinPKevinP
Hugo,

It's unintuitive, but you can use an apex:OutputField to acomplish this.

Try this:
<apex:column width="10" >
  <apex:outputField value="{!tec.Monday__c}" Rendered="{!IF(MONTH(tec.Monday_Date__c) = MONTH(tec_Start_date__c), true, false}"/>
</apex:column>

 

All Answers

KevinPKevinP
Hugo,

It's unintuitive, but you can use an apex:OutputField to acomplish this.

Try this:
<apex:column width="10" >
  <apex:outputField value="{!tec.Monday__c}" Rendered="{!IF(MONTH(tec.Monday_Date__c) = MONTH(tec_Start_date__c), true, false}"/>
</apex:column>

 
This was selected as the best answer
Waqar Hussain SFWaqar Hussain SF
Hello Hugo try the following Code..
<apex:column width="10" value="{!tec.Monday__c}"  rendered="{!IF(MONTH(tec.Monday_Date__c) == MONTH(tec_Start_date__c), true, false)}">

 
Hugo StoupeHugo Stoupe
Thanks both Vickey and Kevin.  Both work great - Kevin's version will leave a spot in the column if the value is blank, where Vicky's will just not output the column at all which creates one less column.  Both have great uses and I appreciate the answers!!    For my application, I need the column left in tact but empty.
Hugo