DataTable - Filter

Filtering updates the data based on the constraints.

Documentation
Search all fields:
IdYear
Brand
Color
Status
All
Sold
Sale
Price
containslteexactinequalscustom (min)
b30ffc911990FordBlueSale$76,568.00
84e55d941967AudiBlueSold$32,184.00
6b84d01c1994HondaBlackSold$39,351.00
218c15bf1994RenaultGreenSale$93,336.00
2ac64a4b1968RenaultSilverSold$2,251.00
f72fc1572003JaguarWhiteSold$77,696.00
1874058a1985BMWWhiteSold$82,930.00
8acc4aaa2004MercedesSilverSold$34,860.00
4982aaf61988RenaultOrangeSold$21,866.00
695791401972FordSilverSold$61,228.00
Search all fields using globalFilterFunction:
IdYearBrandColorStatusPrice
a91601701966VolkswagenRedSale$15,874.00
61e77ae21982VolkswagenGreenSale$68,372.00
5bbe54c91995RenaultBrownSold$97,201.00
f9e55fdf1972BMWWhiteSold$33,252.00
fa3d6e6b1996FiatOrangeSale$22,185.00
c21e7e081991AudiWhiteSold$979.00
8674c3401977AudiBrownSold$13,008.00
7ac922382005FiatBlueSold$42,389.00
8ee685d71969FiatYellowSold$29,077.00
e5d7c16e1980VolkswagenGreenSold$63,725.00
<style type="text/css">
    .ui-datatable {
        margin-bottom: 25px
    }

    .ui-datatable .ui-datatable-header {
        text-align: right !important;
    }

    .ui-button-text-only .ui-button-text {
        padding: 0.3em 0.4em;
    }

    .ui-selectcheckboxmenu-panel .ui-selectcheckboxmenu-header .ui-chkbox {
        visibility: hidden;
    }

    .ui-filter-column .ui-column-customfilter .custom-filter {
        width: 100%;
        box-sizing: border-box;
    }

    .year-spinner input {
        width: 100%;
        box-sizing: border-box;
    }
</style>


<h:form>
    <p:dataTable var="car" value="#{dtFilterView.cars1}" widgetVar="carsTable1"
                 emptyMessage="No cars found with given criteria" filteredValue="#{dtFilterView.filteredCars1}">

        <f:facet name="header">
            <p:outputPanel>
                <h:outputText value="Search all fields:" />
                <p:inputText id="globalFilter" onkeyup="PF('carsTable1').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('carsTable1').filter()" styleClass="year-spinner custom-filter">
                    <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('carsTable1').filter()" styleClass="custom-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('carsTable1').filter()" scrollHeight="150" styleClass="custom-filter">
                    <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('carsTable1').filter()" styleClass="custom-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>

    <p:dataTable var="car" value="#{dtFilterView.cars2}" widgetVar="carsTable2"
                 emptyMessage="No cars found with given criteria" filteredValue="#{dtFilterView.filteredCars2}"
                 globalFilterFunction="#{dtFilterView.globalFilterFunction}">

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

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

        <p:column headerText="Year">
            <h:outputText value="#{car.year}" />
        </p:column>

        <p:column headerText="Brand">
            <h:outputText value="#{car.brand}" />
        </p:column>

        <p:column headerText="Color">
            <h:outputText value="#{car.color}" />
        </p:column>

        <p:column headerText="Status">
            <h:outputText value="#{car.sold ? 'Sold': 'Sale'}" />
        </p:column>

        <p:column headerText="Price">
            <h:outputText value="#{car.price}">
                <f:convertNumber currencySymbol="$" type="currency"/>
            </h:outputText>
        </p:column>
    </p:dataTable>
</h:form>

FREE THEMES

Built-in component themes created by the PrimeFaces Theme Designer.

nova-light Nova-Light
nova-dark Nova-Dark
nova-colored Nova-Colored
luna-blue Luna-Blue
luna-amber Luna-Amber
luna-green Luna-Green
luna-pink Luna-Pink
omega Omega

PREMIUM TEMPLATES

Create awesome applications in no time using the premium templates and impress your users.