angularfiltergridag

Ag Grid setting filter on data ready not applying


I'm trying to filter the data from one column in the grid when the grid had finished the loading of everything it needs. I'm using the Angular version.

I tried this:

  public onFirstDataRendered(params: FirstDataRenderedEvent<MyInterface>): void {
    void params.api
      .setColumnFilterModel('lastUpdatedByUserName', {
        filterType: 'text',
        type: 'equals',
        filter: EMPTY_RESPONSE_VALUE,
      })
      .then(() => {
        params.api.onFilterChanged();
      });
  }

Using this code based on another answers there, nothing happened. I expect the filter to be active on lastUpdatedByUserName column.


Solution

  • Modify your onFirstDataRendered method to use setFilterModel instead of setColumnFilterModel:

    public onFirstDataRendered(params: FirstDataRenderedEvent<MyInterface>): void {
      params.api.setFilterModel({
        lastUpdatedByUserName: {
          filterType: 'text',
          type: 'equals',
          filter: EMPTY_RESPONSE_VALUE,
        },
      });
    
      params.api.onFilterChanged();
    }