DataTable - Filter

Filtering updates the data based on the constraints.

Search all fields:
IdYear
Brand
Color
Status
All
Sold
Sale
Price
containslteexactinequalscustom (min)
c079e7051971HondaRedSold$3,175.00
53bd5f151963VolvoGreenSold$14,111.00
3802b5951965RenaultWhiteSold$4,702.00
e7641dce1962FiatMaroonSale$40,887.00
2db17efd1985JaguarMaroonSold$1,882.00
972234102007AudiYellowSale$43,829.00
fd66bb971975FiatBlueSold$75,839.00
f9ef02e81997AudiBlackSold$55,699.00
c1390eeb1965AudiMaroonSold$66,279.00
3adf1e972007AudiWhiteSale$49,561.00
<style type="text/css">
    .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.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 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('carsTable').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('carsTable').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('carsTable').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>
</h:form>