1
votes

I'm using primefaces Datatable in order to show about 1000 rows (and 7 columns). It's working fast, but I get weird behaviors when I filter a column and try sorting the dataset by a diferent column. Here's an example: In the first picture there is the datatable when it's loaded, looking great. It's heavily censored because I'm working with sensitive data. In the second picture I filter 2 columns, the datatable works fine until there, but if I sort a third column after that, I stops working, no correct row is shown. The values shown there ("não determinado" and a lot of white fields) do not exist in my data.

my datatable when it's loaded and After any combination of filter + sort, it crashes

Here's my code:

<p:dataTable var="prot" value="#{myBean.listaProtocolos}" rows="15" 
 sortBy="#{prot.dataEntradaArea}" sortFunction="#{myBean.sortXMLDatas}" 
 sortOrder="descending" paginator="true" style="font-size: 0.9em;" 
 paginatorPosition="bottom">
  <p:column filterBy="${prot.nrProtocolo}" filterMatchMode="contains" 
   width="8%" style="text-align:center">
    <f:facet name="header">ID</f:facet>
    <p:commandLink action="#{myBean.verDetalhesProtocolo}">
      <h:outputText value="#{prot.nrProtocolo}" 
       style="text-decoration: underline;"/>
      <f:setPropertyActionListener target="#{myBean.nrProtocolo}"
       value="#{prot.nrProtocolo}" />
    </p:commandLink>
  </p:column>
  <p:column filterBy="${prot.nrProcesso}" filterMatchMode="contains"
   width="10%">
    <f:facet name="header">Número</f:facet>
    <h:outputText value="#{prot.nrProcesso}" />
  </p:column>
  <p:column filterBy="${prot.tipoDeProtocoloDescricao}" 
   filterOptions="#{myBean.filtrosTipoDeProtocoloDescricao}" 
   width="10%">
    <f:facet name="header">Processo / Protocolo</f:facet>
    <h:outputText value="#{prot.tipoDeProtocoloDescricao}" />
  </p:column>
  <p:column filterBy="${prot.assunto}" sortBy="#{prot.assunto}"
   filterMatchMode="contains" width="30%">
    <f:facet name="header">Assunto</f:facet>
    <h:outputText value="#{prot.assunto}" />
  </p:column>
  <p:column filterBy="${prot.areaAtual}" sortBy="#{prot.areaAtual}"
   filterMatchMode="contains" width="15%">
    <f:facet name="header">Área Atual</f:facet>
    <h:outputText value="#{prot.areaAtual}" />
  </p:column>
  <p:column filterBy="${prot.tipo}" sortBy="#{prot.tipo}"
   filterMatchMode="contains" width="17%">
    <f:facet name="header">Tipo</f:facet>
    <h:outputText value="#{prot.tipo}" />
  </p:column>
  <p:column filterBy="${prot.dataEntradaAreaFormatada}" 
   sortBy="#{prot.dataEntradaArea}" sortFunction="#{myBean.sortXMLDatas}"
   filterMatchMode="contains" width="10%" style="text-align:center">
    <f:facet name="header">Data de Entrada</f:facet>
    <h:outputText value="#{prot.dataEntradaAreaFormatada}" />
  </p:column>
</p:dataTable>

I'm using primefaces v6.0. myBean is @SessionScoped.

Why is this behavior happening?

2

2 Answers

4
votes

I noticed you are missing an important value in your p:datatable tag and that is filteredValue="" which is a another List similar to value="" which holds the filtered values.

filteredValue="#{myBean.filteredListaProtocolos}"
0
votes

I had similar problem last year. I managed to make a workaround (i was not too happy with it) to use filterFunction=#{mbean.filter} and make my own filter function.