PF Filtering a Datatable column which contains a date

datatable, jsf-2, primefaces

Solution

There is no ready-made date filter mechanism in primefaces yet, but there is a possibility to filter by date using a custom filter. You will have to define a header facet for your column and use ajax calls for "manual" filtering, but it does work:

<column>
  <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>

...

Problem

I have a column in a datatable and I want to add a filter with this code: ``` <p:dataTable id="aDataTable" var="aVariable" value="#{aView.values}" paginator="true" rows="10" selectionMode="single" selection="#{aView.selection}" onRowSelectUpdate="aForm"> <f:facet name="header"> A List </f:facet> <p:column sortBy="#{aVariable.id}" filterBy="#{aVariable.id}" filterEvent="change"> <f:facet name="header"> <h:outputText value="No"/> </f:facet> <h:outputText value="#{aVariable.id}"/> </p:column> <p:column sortBy="#{aVariable.date}" filterBy="#{aVariable.date}" filterEvent="change"> <f:facet name="header"> <h:outputText value="Date"/> </f:facet> </p:dataTable> ``` date is inputted in a form in this format: ``` <h:outputText value="Date: *"/> <p:calendar pattern="dd/MM/yyyy" value="#{aView.value.date}"/> ``` Filter is working for id but not for date. What is the reason for this and how can I make filter work in this case?

Original source