Tuesday, March 9, 2021

Reset ADF table filters programmatically

Requirement-When we use ADF table i.e af:table with filters on each column ,It is very common requirement to clear filter data and reset table result to its initial state.

One way to do is to add af:column as first column in af:table and set rowHeader="true" attribute in af:column.This will show icon in first column to clear filter and reset table results.


There may be a requirement to do this on click of button which is outside af:table .So in this case add below code in button actionListener.



    public void backActionListener(ActionEvent actionEvent) {

        // Add event code here...

        FilterableQueryDescriptor fqd = (FilterableQueryDescriptor)deleteUserTableBinding.getFilterModel();

                      if (fqd != null && fqd.getFilterCriteria() != null) {

                        fqd.getFilterCriteria().clear();

                        deleteUserTableBinding.queueEvent(new QueryEvent(deleteUserTableBinding, fqd));          

                       

                     }

    }

Note: deleteUserTableBinding is my af:table component binding name.(change as per yours)

This will work as long as you are on same page on click of reset button in my case i call it back button. But if are redirecting to different jsff or jspx on click of your reset button above code will throw error saying binding not found because on the page which you are redirecting to does not have table binding iterators and tree binding .


Solution to solve this problem is go to first page's page defination file and copy tree binding and iterator binding ,now paste this in page defination file of next page which you are redirecting to so when we queue event in above code snippet it will find the required binding and wont throw exception.


No comments:

Post a Comment