Problem with Datatable + filter between dates

UI Components for JSF
Post Reply
gapler
Posts: 36
Joined: 11 Jan 2011, 18:50

28 Jul 2016, 14:34

Hi, folks...

I don't know if we have a problem in primefaces at this point, or I'm doing all wrong. The problem is:

I have a datatable:

Code: Select all

        <p:dataTable var="arquivosDisponiveis"  
                     value="#{empresa.arquivosXmlSat}" 
                     selection="#{empresa.selectedArquivoXmlSats}" 
                     paginator="true" rows="20"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} {Exporters}"
                     rowsPerPageTemplate="5,10,15,20,50,100"
                     paginatorPosition="bottom"
                     emptyMessage="No data!"
                     scrollable="true" 
                     style="font-size: 8px;"
                     rowKey="#{arquivosDisponiveis.numeroDocumento}"
                     id="dataTableArquivosSat"
                     reflow="true"
                     widgetVar="TabelaSat"
            >
            <p:column headerText="Número" sortBy="#{arquivosDisponiveis.numeroDocumentoInt}" filterBy="#{arquivosDisponiveis.numeroDocumentoInt}" filterMatchMode="contains" >
                <h:outputText value="#{arquivosDisponiveis.numeroDocumentoInt}" />
            </p:column>

            <p:column headerText="Período" sortBy="#{arquivosDisponiveis.dataEmissaoForFilter}" 
                      filterBy="#{arquivosDisponiveis.dataEmissaoForFilter}"
                      filterFunction="#{dateRangeFilter.filterByDate}"
                      >
                <f:facet name="filter">
                    <h:inputHidden id="filter" />
                </f:facet>
                <f:facet name="header">
                    <p:calendar id="from" pattern="dd/MM/yyyy" value="#{dateRangeFilter.dateFrom}" >
                        <p:ajax event="dateSelect" oncomplete="PF('TabelaSat').filter()" update="from, to, dataTableArquivosSat" />
                    </p:calendar>

                    <p:calendar id="to" pattern="dd/MM/yyyy" value="#{dateRangeFilter.dateTo}">
                        <p:ajax event="dateSelect" oncomplete="PF('TabelaSat').filter()" update="from, to, dataTableArquivosSat" />
                    </p:calendar>                
                </f:facet>
                <h:outputText value="#{arquivosDisponiveis.dataEmissaoForFilter}">
                    <f:convertDateTime type="date" pattern="dd/MM/yyyy"/>
                </h:outputText>
            </p:column>
            
            <p:column headerText="Hora" sortBy="#{arquivosDisponiveis.horaEntradaSaida}" >
                <h:outputText value="#{arquivosDisponiveis.horaEntradaSaida}" />
            </p:column>

        </p:dataTable>
In the column with headerText="Período", I have a customized data range filter:

Code: Select all

public class DateRangeFilter implements Serializable {

    private Date dateFrom;
    private Date dateTo;
    
    public boolean filterByDate(Object value, Object filter, Locale locale) throws ParseException {

        if (this.dateFrom != null && this.dateTo != null ) {
            SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            Date filterDate = formatter.parse((String) value);

            if (value.toString().equals("24/03/2016")) {
                System.out.println ("result is ".concat( String.valueOf( filterDate.after(this.dateFrom) && filterDate.before(this.dateTo) )) );
            }

            return filterDate.after(this.dateFrom) && filterDate.before(this.dateTo);
        } else {
            return true;
        }
    }
}
Look that, in the filterByDate method, I include a printout to show, when the value is "24/03/2016", the same result of the function return.

When I filter the range date between "18/03/2016" and "20/03/2016", I have exactly 54 registers. When the primefaces displays, appears 60 (looks that I specified rows="20" in the datatable). The 6 "extra" registers are, exactly, the registers with date "24/03/2016" - that it printout "false", that means the filterByDate would not return that registers to show up.

I think that may have a problem when specifying rows in datatable. Can anyone confirm it or help me with what I'm doing wrong in my method?

gapler
Posts: 36
Joined: 11 Jan 2011, 18:50

01 Aug 2016, 21:03

no one have the same problem?

gapler
Posts: 36
Joined: 11 Jan 2011, 18:50

18 Aug 2016, 16:08

No one can confirm this? Is that a problem with Primefaces?

gapler
Posts: 36
Joined: 11 Jan 2011, 18:50

27 Sep 2016, 20:28

Sorry... but anyone to confirm this?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests