Primefaces Datatable:按日历过滤

时间:2017-08-21 18:37:20

标签: primefaces jsf-2 calendar filtering

我正在使用PrimeFaces 5.2。我想按日历过滤Primefaces数据表(日期列),如下所示:

enter image description here

我写了这段代码但没有工作:

<p:column filterBy="#{etudiant.dateNaissance}" headerText="Naissance"
            filterMatchMode="exact">
            <f:facet name="filter">
                <p:calendar pattern="yyyy-MM-dd">
                    <p:ajax event="dateSelect"  oncomplete="PF('etudiantTable').filter()" update="dataTable"/>
                    <p:ajax event="change" execute="@this" oncomplete="PF('etudiantTable').filter()" update="dataTable"/>   
                </p:calendar>
            </f:facet>
            <h:outputText value="#{etudiant.dateNaissance}" >
            <f:convertDateTime type="date" pattern="yyyy-MM-dd" /> 
            </h:outputText>
        </p:column>

任何帮助??

1 个答案:

答案 0 :(得分:2)

我找到了解决方案:添加到列日期filterFunction =“myBean.filterByDate”

FilterByDate函数:

public boolean filterByDate(Object value, Object filter, Locale locale) {
    if( filter == null ) {
        return true;
    }

    if( value == null ) {
        return false;
    }

    Date dt2 = (Date) filter;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = sdf.format(dt2);
    boolean status = date2.equals(value.toString());
    return status;
}