Reputation: 1209
i need to filter some fields between dates, but primefaces does not have support for date filtering yet.
i can do it with a function but im not sure how... here is some example i found:
<f:facet name="header">DateRange
<div>
<p:calendar id="from" value="#{bean.from}" styleClass="calendarFilter">
<p:ajax event="dateSelect" listener="#{ctrlr.filterDates()}" update="dataTableId"/>
</p:calendar>
<p:calendar id="to" value="#{bean.to}" styleClass="calendarFilter">
<p:ajax event="dateSelect" listener="#{ctrlr.filterDates()}" update="dataTableId"/>
</p:calendar>
</div>
</f:facet>
there is only the "view" code, id like to see how it would be the filtering function in my bean.
any example would be welcome :)
thanks.
Upvotes: 4
Views: 3964
Reputation: 912
There were I would keep the date fields in a different output panel and based on date select update the table on click of a filter button.
<h:outputText value="FROM" />
<p:calendar id="strtdt" showOn="button" title="Start Date" size="12" value="#{form.startDate}" navigator="true" showButtonPanel="true">
</p:calendar>
<h:outputText value="TO" />
<p:calendar id="enddt" showOn="button" title="End Date" size="12" value="#{form.endDate}"
navigator="true" showButtonPanel="true" >
</p:calendar>
<p:commandButton id="btnFilter" value="Filter" update="datatable" action="#{controller.update()}" ajax="true" />
In the Controller Class write the code to fetch the required data between the dates and update the table (or the list that loads the table). Hope this helps.
Upvotes: 3