DataTable - Filter Filtering updates the data based on the constraints.
Search all fields:
IdYear
Brand
  • Select One
  • BMW
  • Mercedes
  • Volvo
  • Audi
  • Renault
  • Fiat
  • Volkswagen
  • Honda
  • Jaguar
  • Ford
Color
Status
All
Sold
Sale
Price
containslteexactinequalscustom (min)
51c679641992FordYellowSold$89,492.00
5e5faf141981RenaultYellowSale$82,858.00
f06bd70f1991RenaultMaroonSale$41,963.00
6ce95a1e1986VolkswagenBlackSale$8,301.00
36d9ec791984HondaMaroonSale$64,186.00
5566da4e1984VolkswagenBlueSold$93,578.00
f52a05182003BMWBlueSale$67,423.00
30f7da4b1978FordRedSold$84,651.00
0b9e25af1989VolkswagenMaroonSold$37,849.00
0dd2dbe11987AudiBlueSold$30,807.00
<h:form>
    <p:dataTable var="car" value="#{dtFilterView.cars}" widgetVar="carsTable"
                 emptyMessage="No cars found with given criteria" filteredValue="#{dtFilterView.filteredCars}">

        <f:facet name="header">
            <p:outputPanel>
                <h:outputText value="Search all fields:" />
                <p:inputText id="globalFilter" onkeyup="PF('carsTable').filter()" style="width:150px" placeholder="Enter keyword"/>
            </p:outputPanel>
        </f:facet>

        <p:column filterBy="#{car.id}" headerText="Id" footerText="contains" filterMatchMode="contains">
            <h:outputText value="#{car.id}" />
        </p:column>

        <p:column filterBy="#{car.year}" headerText="Year" footerText="lte" filterMatchMode="lte">
            <f:facet name="filter">
                <p:spinner onchange="PF('carsTable').filter()" styleClass="year-spinner">
                    <f:converter converterId="javax.faces.Integer" />
                </p:spinner>
            </f:facet>
            <h:outputText value="#{car.year}" />
        </p:column>

        <p:column filterBy="#{car.brand}" headerText="Brand" footerText="exact" filterMatchMode="exact">
            <f:facet name="filter">
                <p:selectOneMenu onchange="PF('carsTable').filter()" >
                    <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" />
                    <f:selectItems value="#{dtFilterView.brands}" />
                </p:selectOneMenu>
            </f:facet>
            <h:outputText value="#{car.brand}" />
        </p:column>

        <p:column filterBy="#{car.color}" headerText="Color" footerText="in" filterMatchMode="in">
            <f:facet name="filter">
                <p:selectCheckboxMenu label="Colors" onchange="PF('carsTable').filter()" panelStyle="width:125px" scrollHeight="150">
                    <f:selectItems value="#{dtFilterView.colors}" />
                </p:selectCheckboxMenu>
            </f:facet>
            <h:outputText value="#{car.color}" />
        </p:column>

        <p:column filterBy="#{car.sold}" headerText="Status" footerText="equals" filterMatchMode="equals">
            <f:facet name="filter">
                <p:selectOneButton onchange="PF('carsTable').filter()">
                    <f:converter converterId="javax.faces.Boolean" />
                    <f:selectItem itemLabel="All" itemValue="" />
                    <f:selectItem itemLabel="Sold" itemValue="true" />
                    <f:selectItem itemLabel="Sale" itemValue="false" />
                </p:selectOneButton>
            </f:facet>
            <h:outputText value="#{car.sold ? 'Sold': 'Sale'}" />
        </p:column>

        <p:column filterBy="#{car.price}" headerText="Price" footerText="custom (min)" filterFunction="#{dtFilterView.filterByPrice}">
            <h:outputText value="#{car.price}">
                <f:convertNumber currencySymbol="$" type="currency"/>
            </h:outputText>
        </p:column>
    </p:dataTable>
</h:form>
                
PrimeTek, Copyright © 2015
All rights reserved.
Running PrimeFaces-6.1-SNAPSHOT on Mojarra-2.2.8.