Core Features

Advanced Features

Angular Data GridExternal Filter

Version 36.2.0

External filtering allows custom filtering logic to be mixed with the grid's inbuilt filtering.

This form of filtering is only compatible with the Client-Side Row Model, see Row Models for more details.

Implementing External Filtering Copy Link

The example above shows external filters in action. Two methods on gridOptions are required to be implemented: isExternalFilterPresent and doesExternalFilterPass.

isExternalFilterPresentCopy Link
IsExternalFilterPresent
Grid calls this method to know if an external filter is present. Called exactly once every time the grid senses a filter change. Should return true if external filtering is active, otherwise false. If true, doesExternalFilterPass is called while filtering, otherwise it is not called. Supplying a new function reference re-runs external filtering.
doesExternalFilterPassCopy Link
DoesExternalFilterPass
Called once for each row node in the grid. Should return true if external filter passes, otherwise false. If false, the node is excluded from the final set. Only runs if isExternalFilterPresent returns true. Supplying a new function reference re-runs external filtering.

Re-running the External Filter Copy Link

The filter state is held outside the grid, so the grid has to be told when that state has changed. Pick one of the following approaches:

  • Calling onFilterChanged - the callback references are kept stable and the filter is re-run only when the API is called.
  • Supplying New Callbacks - a new callback reference is handed to the grid and the filter is re-run automatically.

Calling onFilterChanged Copy Link

After the filter state has changed call api.onFilterChanged() to ask the grid to run filtering again.

onFilterChangedCopy Link
FilterChangedEventSourceType
Informs the grid that a filter has changed. This is typically called after a filter change through one of the filter APIs. source: The source of the filter change event. If not specified defaults to 'api'.
// Filter state updated now re-run filtering
api.onFilterChanged();

Ensure the callbacks have stable references to avoid triggering filtering excessively.

A template binding is re-evaluated on every change-detection run, and .bind(this) returns a new function each time it is evaluated so the grid re-filters on every cycle:

<ag-grid-angular [isExternalFilterPresent]="isExternalFilterPresent.bind(this)" />

Prefer an arrow function defined on the component instead as the reference is stable for the lifetime of the component.

Supplying New Callbacks Copy Link

isExternalFilterPresent and doesExternalFilterPass are reactive grid properties, so replacing either one with a new function re-runs filtering automatically.

Where the filter state is held in a signal, each callback is exposed as a computed that returns the filter function, and the invoked signal is bound in the template. A change to the state signal recomputes the callback, so the grid is given a new reference and re-runs filtering:

@Component({
    template: `<ag-grid-angular [doesExternalFilterPass]="doesExternalFilterPass()" />`,
})
export class AppComponent {
    public minAge = signal(0);

    public doesExternalFilterPass = computed(() => {
        const minAge = this.minAge();
        return (node: IRowNode<IOlympicData>) => node.data!.age > minAge;
    });
}

The state signal is read outside the returned function so that it is a dependency of the computed. Reading it inside the returned function instead leaves the computed with no dependencies, and the reference never changes.

Reassigning a plain class field hands the grid a new reference in the same way:

// reassigning the field hands the grid a new reference, and filtering re-runs
this.doesExternalFilterPass = (node: IRowNode<IOlympicData>) => node.data!.age > this.minAge;

The example on this page takes the second path: ageType is a signal, and both callbacks are computed values that read it.