Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primefaces:datatable: custom filter: "contains" instead of "beginning"

By default, primeface filter dataTable's rows, by finding rows that columns begins with the string entered in the search area. How do I filter the DataTable rows that the column contains (not begins with) the string entered in the search area?

like image 808
Zarnis Avatar asked Dec 15 '22 11:12

Zarnis


1 Answers

You can do this using filterMatchMode attribute on p:column of the dataTable. A very good example can be found on PrimeFaces showcase.

So if we take the above mentioned example, you could have roughly something like this:

<p:dataTable var="car" value="#{dtFilterView.cars}" widgetVar="carsTable"
    filteredValue="#{dtFilterView.filteredCars}">

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

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

The attribute filterMatchMode accepts values such as contains, endsWith, startsWith, exact...

like image 106
Sva.Mu Avatar answered Jun 19 '23 02:06

Sva.Mu