React Data GridSet Filter - API

Enterprise

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

Set Filter Model Copy Link

Get and set the state of the Set Filter by getting and setting the model on the grid API.

// 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.

filterTypeCopy Link
'set'
'set'
valuesCopy Link
SetFilterModelValue
SetFilterModelValue

Set Filter API Copy Link

The Set Filter values can be updated via the Set Filter Handler:

// get filter handler
const countryFilterHandler = gridApi.getColumnFilterHandler('country');

The SetFilterHandler interface defines the public API for the Set Filter Handler.

Properties available on the SetFilterHandler<TValue = string> interface.

getFilterKeysCopy Link
Function
Returns the full list of unique keys used by the Set Filter.
getFilterValuesCopy Link
Function
Returns the full list of unique values used by the Set Filter.
setFilterValuesCopy Link
Function
Sets the values used in the Set Filter on the fly.
refreshFilterValuesCopy Link
Function
Refreshes the values shown in the filter from the original source. For example, if a callback was provided, the callback will be executed again and the filter will refresh using the values returned.
resetFilterValuesCopy Link
Function
Resets the Set Filter to use values from the grid, rather than any values that have been provided directly.

The Mini Filter get by interacted with via the Set Filter instance:

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

The SetFilterUi interface defines the public API for the Set Filter component.

Properties available on the SetFilterUi interface.

getMiniFilterCopy Link
Function
Returns the current mini-filter text.
setMiniFilterCopy Link
Function
Sets the text in the Mini Filter at the top of the filter (the 'quick search' in the popup).

In the example below, you can see how the filter for the Athlete column is modified through the API.

Enabling Case-Sensitivity Copy Link

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

const [columnDefs, setColumnDefs] = useState([
    {
        field: 'colour',
        filter: 'agSetColumnFilter',
        filterParams: {
            caseSensitive: true
        }
    }
]);

<AgGridReact columnDefs={columnDefs} />

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. This is printed to the developer console.

Next Up Copy Link

Continue to the next section to learn about Multi Filters.