Monday, May 30, 2016

ADF: af:table filter modifications using a custom Query Listener

In one of our last projects we had the requirement to allow the user to filter tables using the table filter feature. By default you can filter String fields starting with the word that the user provides, but our customer needed to find the rows that contained the criteria.

This is an easy task that can be accomplished by creating a custom Query Listener method.


As by default the filter works with "Starts with" condition you will see that filtering by "tra" will give no result although departments like Administration exists.
In this example we will use Departments table in HR schema.


When we drag and drop to create a table and we set it to be filterable, we can see that a query listener has been created by default.


As we need to modify the filter values we need to create ouor own query listener.

The idea of this method is to get every value, and if it is String we have to change the original value and concatenate '%' before and after the value.

After that we need to call the default query listener that we can get from queryListener property in the table component.

If we end here, the  user would see the new filter with % symbol, so we are going to remove it and leave it as the user type it.


This is the helper method we use to call the default  query listener.


The last step is to set our new method as the table's query listener.


If we run the application we can see that if we filter by "tra", we can now see some records.


No comments:

Post a Comment