Angular Data GridSet Filter - API
angular logo
Enterprise

This section describes how the Set Filter can be controlled programmatically using API calls.

Set Filter Model

Get and set the state of the Set Filter by getting and setting the model on the filter instance.

// get filter model
const model = api.getColumnFilterModel('country');
 
// set filter model and update
await api.setColumnFilterModel('country', { values: ['Spain', 'Ireland', 'South Africa'] });
 
// refresh rows based on the filter (not automatic to allow for batching multiple filters)
api.onFilterChanged();

The filter model contains an array of string values where each item in the array corresponds to an element to be selected from the set.

Properties available on the SetFilterModel interface.

Set Filter API

The Set Filter instance can be retrieved via the getColumnFilterInstance API method.

// get filter instance
this.gridApi.getColumnFilterInstance('country').then(countryFilterComponent => {
    // use set filter instance
});

The ISetFilter interface defines the public API for the Set Filter.

Properties available on the ISetFilter<V = string> interface.

See: Refreshing Values

It is important to note that when updating the Set Filter through the API, it is up to the developer to call filterInstance.applyModel() to apply the changes that have been made to the model and then api.onFilterChanged() at the end of the interaction with the filter.

If no call is made to filterInstance.applyModel() then the filter UI will show any changes, but they won't be reflected in the filter model. This will appear as if the user never hit the Apply Button (regardless of whether the Apply Button is active or not).

If no call to api.onFilterChanged() is provided the grid will still show the data relevant to the filter before it was updated through the API.

In the example below, you can see how the filter for the Athlete column is modified through the API and how at the end of the interaction a call to api.onFilterChanged() is performed.

Enabling Case-Sensitivity

By default the API is case-insensitive. You can enable case sensitivity by using the caseSensitive: true filter parameter:

<ag-grid-angular
    [columnDefs]="columnDefs"
    /* other grid options ... */>
</ag-grid-angular>

this.columnDefs = [
    {
        field: 'colour',
        filter: 'agSetColumnFilter',
        filterParams: {
            caseSensitive: true
        }
    }
];

The caseSensitive option also affects Mini-Filter searches and the values presented in the Filter List.

The following example demonstrates the difference in behaviour between caseSensitive: false (the default) and caseSensitive: true:

  • With caseSensitive: false (the default):
    • setModel() will perform case-insensitive matching against available values to decide what is enabled in the Filter List.
    • setFilterValues() will override the available values and force the case of the presented values in the Filter List to those provided.
      • Selected values will be maintained based upon case-insensitive matching.
  • With caseSensitive: true:
    • setModel() will perform case-sensitive matching against available values to decide what is enabled in the Filter List.
    • setFilterValues() will override the available values and force the case of the presented values in the Filter List to those provided.
      • Selected values will be maintained based upon case-sensitive matching.
  • In both cases getModel() and getFilterValues() will return the values with casing that matches those displayed in the Filter List.

Next Up

Continue to the next section to learn about Multi Filters.