PF过滤包含日期的Datatable列 [英] PF Filtering a Datatable column which contains a date

查看:176
本文介绍了PF过滤包含日期的Datatable列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表中的列,我想添加一个带有以下代码的过滤器:

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}"/>

过滤器适用于ID,但不适用于日期。这样做的原因是什么?如何在这种情况下过滤工作?

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?

推荐答案

没有现成的日期过滤器机制的原理,但有可能按日期过滤使用自定义过滤器。您必须为列定义一个标题构面,并使用ajax调用进行手动过滤,但它可以正常工作:

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>

...

这篇关于PF过滤包含日期的Datatable列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆