title: How to implement global filter in a primefaces datatable using lazy loading?
body: <p>I have an implementation of lazyDataModel following this tutorial <a href="http://uaihebert.com/?p=1120" rel="nofollow noreferrer">http://uaihebert.com/?p=1120</a></p>
  <p>My code its a bit different from this tutorial, here it is:</p>
  <p>View:</p>
  <pre><code>&lt;p:dataTable id=&quot;tablaClientes&quot;  value=&quot;#{AgendaManualMBean.allClientes}&quot; 
     var=&quot;tablaClientes&quot; 
     widgetVar=&quot;clienteTable&quot; 
     rowKey=&quot;#{tablaClientes.clDocid}&quot; 
     selection=&quot;#{AgendaManualMBean.ciatt001}&quot; selectionMode=&quot;single&quot;  rows=&quot;10&quot; 
     lazy=&quot;true&quot; paginatorPosition=&quot;top&quot; 
     paginatorTemplate=&quot;{RowsPerPageDropdown}{FirstPageLink}{PreviousPageLink} 
     {CurrentPageReport} {NextPageLink} {LastPageLink}&quot; rowsPerPageTemplate=&quot;5,10,15&quot;
     emptyMessage=&quot;No existen clientes&quot;&gt;
  
                  &lt;f:facet name=&quot;header&quot; &gt;  
                      &lt;p:outputPanel&gt;  
                          &lt;h:outputText value=&quot;Busqueda &quot; /&gt;  
                          &lt;p:inputText id=&quot;globalFilter&quot; onkeyup=&quot;clienteTable.filter()&quot; 
                           style=&quot;width:150px&quot;  size=&quot;10&quot;/&gt;  
                      &lt;/p:outputPanel&gt;  
                  &lt;/f:facet&gt;  
  
                  &lt;p:column id=&quot;numOrdenColumn&quot; filterBy=&quot;#{tablaClientes.clDocid}&quot;  
                            width=&quot;50&quot;              
                            headerText=&quot;Identificación&quot; 
                           
                            filterMatchMode=&quot;contains&quot;&gt;  
                      &lt;h:outputText value=&quot;#{tablaClientes.clDocid}&quot; /&gt;  
                  &lt;/p:column&gt;  
                  &lt;p:column id=&quot;nomCliColumn&quot; 
                            filterBy=&quot;#{tablaClientes.clNombre1}&quot;   
                            width=&quot;250&quot;
                        
                            headerText=&quot;Cliente&quot; 
                            filterMatchMode=&quot;contains&quot;&gt;  
                      &lt;h:outputText value=&quot;#{tablaClientes.clNombre1}&quot; /&gt;  
                  &lt;/p:column&gt;  
  
              &lt;/p:dataTable&gt; 
  </code></pre>
  <p>MY Managed Bean:</p>
  <pre><code> public LazyDataModel&lt;Ciatt001&gt; getAllClientes() {
      if (listaClientesLazy == null) {
          listaClientesLazy = new LazyClienteModel(ambiente.getCodCia(),ambiente.getCodAge());
          //listaClientesLazy = new LazyClienteModelMBean();
      }
  
      return listaClientesLazy;
  }
  </code></pre>
  <p>My LazyDataModel</p>
  <pre><code>public List&lt;Ciatt001&gt; load(int startingAt, int maxPerPage, String sortField, SortOrder sortOrder, Map&lt;String, String&gt; filters) {
      String a = &quot;&quot;;
      try {   
      listaClientes = new ArrayList&lt;Ciatt001&gt;();
      a = String.valueOf(agendamientoSession.countClientes2(cia, age));
      listaClientes = agendamientoSession.listaClientes2(cia, age, startingAt, maxPerPage);
      } catch (Exception e) {
          e.printStackTrace();
      }
      
      if (getRowCount() &lt;= 0) {
        setRowCount(Integer.parseInt(a));
       }
      setPageSize(maxPerPage);
       return listaClientes;  
      }
  
  @Override
  public Object getRowKey(Ciatt001 ciatt001) {
      return ciatt001.getClDocid();
  }
  
  @Override
  public Ciatt001 getRowData(String docid) {
      //Integer id = Integer.valueOf(idBandeja);
  
      for (Ciatt001 ciatt001 : listaClientes) {
          if (docid.equals(ciatt001.getClDocid())) {
              return ciatt001;
          }
      }
  
      return null;
  }       
  </code></pre>
  <p>And the ejb methods:</p>
  <pre><code> public List&lt;Ciatt001&gt; listaClientes2(String cia, String age  ,int startingAt, int maxPerPage) {
  
      Query query = em.createNamedQuery(&quot;Ciatt001.listaClientesPorCiaPorAge2&quot;);
      query.setParameter(1, cia);
      query.setParameter(2, age);
      query.setFirstResult(startingAt);
      query.setMaxResults(maxPerPage);
      return query.getResultList();
  }
      public String countClientes2(String cia, String age) {
  
      Query query = em.createNamedQuery(&quot;Ciatt001.countClientes2&quot;);
      query.setParameter(1, cia);
      query.setParameter(2, age);     
      return query.getSingleResult().toString();
  }
  </code></pre>
  <p>How can I achieve a global filter using this lazy loading implementation?</p>