Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
784 views
in Technique[技术] by (71.8m points)

jsf 2 - PF Filtering a Datatable column which contains a date

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...