Primefaces datatable filter doesn't work

前端 未结 5 1770
萌比男神i
萌比男神i 2020-12-21 06:04

I must do something fundamentally wrong, I stripped down the code to the bare minimum with a data table and enabling one column filter and a globe filter.

The funny

相关标签:
5条回答
  • 2020-12-21 06:43

    Please see lazy property this may be that your data not filter.

    lazy="true" change lazy=false

    0 讨论(0)
  • 2020-12-21 06:45

    finally I figured out that when you use Lazy the filtered data is not stored in other variable as in non lazy implementation, everytime you call a filter the load method is executed, so I had to put the filters also in my Load, also the sorting this is the way when using Lazy.

    My mistake !

    0 讨论(0)
  • 2020-12-21 06:48

    You should initialize filtredProjects with the same data that contains the ArrayList allProjects like this:

    @PostConstruct
    public void loadAllProjects(){
    allProjects =  projectEJB.getAllProjects();
    filtredProjects = projectEJB.getAllProjects();
    }
    
    0 讨论(0)
  • 2020-12-21 06:48

    Do not use lazy loading when filtering and/or sorting

    0 讨论(0)
  • 2020-12-21 06:59

    The filters features of p:dataTable need to be wrapped in <h:form> tags for work fine. The code xhtml modified would:

    <!DOCTYPE html>
    <html xmlns="http://www.w3c.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui">
    
    <ui:composition template="layout.xhtml">
    
        <ui:define name="title">All Projects</ui:define>    
    
        <ui:define name="content">
           <h:form>
               <p:dataTable var="project" value="#{projectController.allProjects}" widgetVar="projectTable" filteredValue="#{projectController.filteredProjects}">
    
                  <f:facet name="header">
                    <p:outputPanel>  
                        <h:outputText value="Search all fields:" />  
                        <p:inputText id="globalFilter" onkeyup="PF('projectTable').filter()" style="width:150px" />  
                     </p:outputPanel>
                  </f:facet>
    
                  <p:column headerText="Name" filterBy="#{project.name}">
                     <h:outputText value="#{project.name}" />
                  </p:column>
    
                  <p:column headerText="Priority">
                     <h:outputText value="#{project.priority}" />
                  </p:column>
    
                 <p:column headerText="Exit">
                     <h:outputText value="#{project.exitCriteria}" />
                 </p:column>
    
              </p:dataTable>      
          </h:form>
       </ui:define>
    </ui:composition>
    
    0 讨论(0)
提交回复
热议问题