Search code examples
javascriptangularangular2-directivesag-gridag-grid-ng2

Angular 2 ag-grid's Clear Filter button clears the textbox without refreshing column when built-in filter is used


When ag-grid's default filter is enabled, the clear filter button only clears the text box and doesn't refresh the column even though 'clearButton' and 'applyButton' params are set to true. After clicking the Clear filter button the text gets cleared from the textbox and I have to actually click Apply Filter button to remove the filter and refresh the column.

Below is my code:

 result.filter = "date";
 result.filterParams = {
     applyButton: true,
     clearButton: true
 };

Is there a way where we can make Clear Filter button actually refresh the column along with clearing text box? Or is there any event available for clear button click which we can subscribe to? (in documentation there isn't any event mentioned for clear button click)

Help will be appreciated


Solution

  • A listener can be attached to click event of some specific filter's clear button and inside listener we can call this.gridOptions.api.onFilterChanged() to trigger the change.

    let filterInstance = this.gridOptions.api.getFilterInstance("name_col");
    
    filterInstance.eClearButton.addEventListener("click", () => {
        this.gridOptions.api.onFilterChanged();
     });