Thursday, March 30, 2017

Primefaces filter datatable by name

There are sometimes when we need to filter data on a datatable, the best way to do it is this one where

listaProductos is a List<Productos>
listaProductosfiltrados is a List<Productos> this list is the one load on memory the one who are filter


this one is the one who make possible and with    filteredValue="#{creacionElementos.listaProductosfiltrados}"

<p:column filterBy="#{pl.nombreProducto}" headerText="Nombre" filterMatchMode="contains">
            <h:outputText value="#{pl.nombreProducto}" />
        </p:column>
                               

<p:dataTable id="tabla2" var="pl"
                                    value="#{creacionElementos.listaProductos}" reflow="true"

                                   
                                   
                                    selection="#{creacionElementos.productoSeleccionados}"
                                    rowKey="#{pl.id}"
                                   

                                    filteredValue="#{creacionElementos.listaProductosfiltrados}"
                                  
                                    >


                                    <f:facet name="header">
       Productos
    </f:facet>
                                


<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
                              
                              
                                 <p:column filterBy="#{pl.nombreProducto}" headerText="Nombre" filterMatchMode="contains">
            <h:outputText value="#{pl.nombreProducto}" />
        </p:column>
                              
                               
   
    <p:column headerText="Estado">
        <h:outputText id="nombre4" value="#{pl.estado}" />
    </p:column>

                                </p:dataTable>