0
votes

How can I filter Date column in Datatable in dd//mm/yyyy pattern ? I'm using Primefaces 5.2 Community edition.

<p:column sortBy="#{user.date}" styleClass="date"
    filterBy="#{user.date}" id="date">

        <h:outputText value="#{user.date}">
            <f:convertDateTime type="date" pattern="dd/MM/yyyy" />
        </h:outputText>
        <p:watermark for="@(.date)" value="#{msg['dateOfBirth']}" />

</p:column>

Filtering without a converter works, but with the converter is does not work anymore

2
Since PrimeFaces 5.0, any input component can be placed inside <f:facet name="filter"> which acts as a column filter. Filtering a result list by dates is then no longer different than filtering it by using other type of values.Tiny
Yes there is no problem in filtering, but the real problem is how to filter in dd/mm/yyyy patterncoderxyz24

2 Answers

0
votes

This works just fine for me.

<p:column headerText="Data " filterBy="#{user.date}">
    <h:outputText value="#{user.date}" />

But may be im not geting whats ur real problem is.

Edit.

I copy pasted ur code and it works fine for me...

<p:column sortBy="#{odczyt.data_odczytu}" 
filterBy="#{odczyt.data_odczytu}" id="date">
    <h:outputText value="#{odczyt.data_odczytu}">
        <f:convertDateTime type="date" pattern="dd/MM/yyyy" />
    </h:outputText>
    <p:watermark for="@(.date)" value="#{msg['dateOfBirth']}" />

You must remember that the filter doesnt see your date in converted format but in orginal form that comes from your backing bean. So when u have a date in 'yyyy-MM-dd' format and use converter 'pattern="dd/MM/yyyy"', in filter field u must use same pattern as original bean format, for example '2015-05-03'.

-3
votes

Don't format date in view but rather convert and format as string the backing bean.

view

 <p:column sortBy="#{user.dateAsString}" styleClass="date" 
      filterBy="#{user.dateAsString}" id="date">
    <h:outputText value="#{user.dateAsString}">
 </p:column>

backing bean

public String getDateAsString() {
    Format formatter = new SimpleDateFormat("dd/mm/yyyy");
    return formatter.format(date);
}