Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces dataTable applying filter on multiple field in a single column

I have a p:datatable which lists users. One of the column contains the concatenated First Name + Last Name of the user and I'd like to be able to filter on both these values in the same 'filter field' so that it tries to match the filter on the name as well as on the first name.

i.e.: users: "Bob Green" and "Steve Ross", if I enter the filter 'o', both users will appear in the filtered list.

The dataTable:

<p:dataTable id="users" 
                   value="#{userCtrl.userList}" 
                   filteredValue="#{userCtrl.filteredUserList}"
                   var="user"
                   sortMode="multiple">

         <!-- FIRST NAME + LAST NAME -->
         <p:column id="col_name" 
                   filterBy="#{user.name} ADD SOMETHING HERE FOR FIRST NAME?" 
                   headerText="Name"
                   filterMatchMode="contains">
            <h:outputText value="#{user.firstName} #{user.lastName}" />
         </p:column>



</p:dataTable>

Both the attributes firstName and lastName are Strings.

Any ideas if something like this is doable ?

Thank you!

like image 309
Yannick Avatar asked Feb 15 '23 17:02

Yannick


1 Answers

This should work

filterBy="#{user.firstName} #{user.lastName}"
like image 69
fareed Avatar answered Feb 18 '23 06:02

fareed