Set Filter - Data Updates

This section describes how changing data through Cell Editing and the application Updating Data impacts the Set Filter's values. This is only applicable when the Set Filter is taking its values form the grid's data.

Row / Cell Updates

Row / Cell updates refers to any of the following:

Filter Values will be refreshed when data is updated through any of these methods.

Here are the rules that determine how Filter Values are selected:

  • Filter Inactive: Before the update 'all' values in the filter were selected (as the filter was inactive). The filter list will be updated reflecting the data change and all values will remain selected leaving the filter inactive
  • Filter Active: Before the update 'some' values in the filter were selected (as the filter was active). The filter list will be updated reflecting the data change, however previous selections will remain intact. If the update resulted in a new filter value, the new filter value will not be selected.

Cell editing does not re-execute filtering by default, so the row will not be filtered out even though the value in the cell is not selected in the filter. This default behaviour mimics how Excel works.

To execute filtering on cell edits, listen to CellValueChanged events and trigger filtering as shown below:

gridOptions: { onCellValueChanged: function(params) { // trigger filtering on cell edits params.api.onFilterChanged(); } // other options }

The following example demonstrates Cell Editing with the Set Filter. Try the following:

Without selecting any Filter Values:

  • Change (Cell Edit) a 'B' cell value to 'X' and note it gets added to the filter list and is selected.

Click 'Reset' and deselect 'C' in the Filter List:

  • Change (Cell Edit) a 'B' cell value to 'X' and notice it gets added to the Filter List but it is not selected.
  • Note that although 'X' is not selected in the filter the row still appears in the grid. This is because grid filtering is not triggered for cell edits.

Transaction Updates

Transaction Updates refers to any of the following:

Filter values are refreshed when data is updated using any of these methods.

Here are the rules that determine how filter values are selected:

  • Filter Inactive: Before the update 'all' values in the filter were selected (as the filter was inactive). The filter list will be updated reflecting the data change and all values will remain selected leaving the filter inactive
  • Filter Active: Before the update 'some' values in the filter were selected (as the filter was active). The filter list will be updated reflecting the data change, however previous selections will remain intact. If the update resulted in a new filter value, the new filter value will not be selected.

Unlike Cell Editing, transaction updates will execute filtering in the grid.

The following example demonstrates these rules. Try the following:

Without selecting any filter values:

  • Click Update First Displayed Row: this calls api.applyTransaction() and updates the value in the first row. Note 'AX' now appears in the filter list and is selected.
  • Click Add New 'D' Row: this calls api.applyTransaction() and adds a new row to the grid. Note 'D' has been added to the filter list and is selected.

Click 'Reset' and deselect 'C' in the Filter List:

  • Click Update First Displayed Row: this calls api.applyTransaction() and updates the value in the first row. Note 'AX' now appears in the filter list and is not selected.
  • Note that as 'AX' is unselected in the filter list it has also been filtered out of the grid. This is because transaction updates also triggers grid filtering.
  • Click Add New 'D' Row: this calls api.applyTransaction() and adds a new row to the grid. Note 'D' has been added to the filter list and is not selected.

Setting New Data

By default, when api.setRowData() is called, all Set Filter selections will be lost.

It is recommended that newRowsAction='keep' is set on the filter params to keep existing filter selections when new rows are added, as shown below:

// ColDef { field: 'col1', filter: 'agSetColumnFilter', filterParams: { newRowsAction: 'keep' } }
newRowsAction is deprecated, and newRowsAction='keep' will become the default behaviour in v24.

However it is still possible to clear filter selections using: api.setFilterModel([]).

The following example demonstrates how api.setRowData() affects filter selections. Try the following:

  • Deselect value 'B' from the set filter list and click the Set New Data button which calls api.setRowData(newData) to add new data with extra rows to the grid.
  • Notice 'B' remains deselected after new data is supplied to the grid as the set filter has set newRowsAction='keep' in the filter params.
  • Clicking Reset invokes api.setRowData(origData) to restore the original data but also clears any selections using api.setFilterModel([]).

Next Up

Continue to the next section: Mini Filter.