Mirage LIVE PREVIEW

DataTable - Filter

Filtering updates the data based on the constraints.

Documentation
Search all fields:
IdYear
Brand
Color
Status
All
Sold
Sale
Price
containslteexactinequalscustom (min)
db8f1f7d1966FiatGreenSold$53,074.00
7b73098f2004MercedesYellowSold$48,635.00
090ddb401985VolkswagenBlueSold$36,482.00
fdc9f2f11984FiatSilverSold$51,607.00
4540a9892000BMWBrownSold$60,124.00
21bad5421996FiatSilverSold$69,100.00
fe9975a01987HondaOrangeSale$84,109.00
d608bec51975VolvoBrownSold$19,394.00
f2dcf0781996JaguarOrangeSold$34,953.00
0237e1d71973HondaBrownSale$60,392.00
Search all fields using globalFilterFunction:
IdYearBrandColorStatusPrice
6bebe13d1998HondaOrangeSold$35,192.00
efa8f0a92007MercedesBlueSold$3,506.00
ca5cbf862003VolvoMaroonSale$19,014.00
2e3565ca1973JaguarGreenSale$37,286.00
0b92fdfa1995RenaultRedSale$71,379.00
776bf6912009MercedesBlueSold$71,827.00
fd9c56a81974MercedesSilverSale$6,773.00
943242391998VolvoOrangeSold$33,963.00
6ed2cbd12009AudiWhiteSale$55,033.00
f1090c601993MercedesBlueSale$57,247.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>