0
votes

I am new to jsf and would like to know how to perform data filter in primefaces datatable. I want when a user start typing on the search text field to filter all records and eventually left with the value in the search text field. How can I achieve this in jsf datatable I am using primefaces 3.5. here is my datatable and corresponding managed bean.

  <p:tabView dynamic="true" id="tabview" cache="true" style="min-height: 500px;">
                    <p:tab title="first Tab">

                             <h:form >
                                        <p:dataTable paginator="true" value="#{mybean.allusers}" var="user" id="user_table" widgetVar="userTable">
        <p:outputPanel>
            <h:outputText value="Search all fields:" />
            <p:inputText id="globalFilter" onkeyup="PF('userTable').filter()" style="width:150px" placeholder="Enter keyword"/>
        </p:outputPanel>
                                      <p:column>
                                          <f:facet name="header">
                                              <h:outputText value="Name"/>
                                          </f:facet>
                                          <h:outputText value="#{user.name}"/>
                                      </p:column>
                                      <p:column>
                                          <f:facet name="header">
                                              <h:outputText value="Id"/>
                                          </f:facet>
                                          <h:outputText value="#{user.id}"/>
                                      </p:column>
                                  </p:dataTable>
                            </h:form


                     </p:tab>
    </p:tabView >


import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import javax.faces.context.FacesContext;
@ManagedBean
@ViewScoped
        private  List<Users> filteredUsers;
      public List<RevenueGroup> getFilteredUsers() {
    return filteredGroups;
     }
public void setFilteredGroups(List<Users> filteredUsers) {
    this.filteredUsers = filteredUsers;
}
public List<Users> getAllusers() {
if(grps==null)
{
 grps=UserDao.getUser();
}
 return grps;
}
1

1 Answers

0
votes

Primeface provides inbuild data table filters. Check the below link

DataTable - Filter

See FilterView.java in the same page where you can see how filters are implemented.

Also consider upgrading primeface, latest version is 5.3.