[SalesForce] Hide column in pageBlockTable based on day

I have a pageBlockTable whose column headers are dynamically generated based on the date. I would like to hide any column whose date falls on a Sunday. Below is the sample of the code for one of the columns.

<apex:column >
    <apex:facet name="header">
        <apex:outputPanel >
            <apex:outputText value="{0, date, EEEE}">
                <apex:param value="{!NOW()}" />
            </apex:outputText>
        </apex:outputPanel>
    </apex:facet>
    <apex:outputText value="{!Appointment.Open__c}"/>
</apex:column>

Is it possible to set the rendered attribute of the column to the result of the boolean expression of whether the current day is Sunday?

Best Answer

VF route would be to do :

<apex:column rendered="{!IF((MOD(DATEVALUE(TEXT(today())) - DATE(0001,1,1),7))==1,false,true)}"/>

(OR)

IF you have a controller, get today's day using

Reference : How Can I Tell the Day of the Week of a Date?

declare a boolean

public boolean rendercolumn{get;set;}

initialize in constructor

rendercolumn= true;

in your pageblocktable / datatable method add:

Date d = System.today();
Datetime dt = (DateTime)d;
String dayOfWeek = dt.format('EEEE');
if(dayofweek == "Sunday"){
rendercolumn = false;
}

VF Page:

<apex:column rendered="{!rendercolumn}">
Related Topic