Core Features

Advanced Features

React Data GridNew Filters Tool Panel

Version 36.3.0
Enterprise

The new Filters Tool Panel allows accessing the grid's filters without needing to open up the column menu.

Enabling New Filters Tool Panel Copy Link

To use the new Filters Tool Panel, set enableFilterHandlers = true, and use the 'filters-new' Side Bar Configuration.

If a filter is set from anywhere outside of the tool panel, e.g. from the column menu, the filter will automatically be added to the tool panel. Once a filter appears in the tool panel, it will remain until it's removed from within the tool panel. Removing a filter from the tool panel also clears that filter.

Using Buttons Copy Link

The tool panel can be configured to have global Apply, Clear, Reset and Cancel Buttons. These behave the same as when used within an individual filter, but instead apply to all filters at once.

To use global buttons, every filter must first be configured to use the buttons. The global buttons can then be passed to the tool panel configuration when using agNewFiltersToolPanel, by passing an IToolPanelNewFiltersCompParams object:

buttonsCopy Link
FilterAction[]
Allows global buttons to be provided to the filter tool panel

The example below demonstrates using buttons with the tool panel:

Note that when opened from the column menu, the buttons will be visible within the individual filters. Within the tool panel, only the global buttons will be visible.

Configuring Filters Copy Link

Changing Selectable Filters Copy Link

For each column filter, the filter type can be changed by using the dropdown within the tool panel. To enable switching filters, set filter: 'agSelectableColumnFilter' on the column definition. For any other filter value, the dropdown will not be displayed.

By default, the dropdown will allow switching between:

To allow other filters to be configured in the dropdown, filterParams of type SelectableFilterParams can be set on the column definition:

filtersCopy Link
SelectableFilterDef[]
List of possible filters which will show in the filter card. If not provided, will default to grid-provided filters
defaultFilterIndexCopy Link
number
The index of the filter that should be active by default, in filters or else in the default list. Without one the first is active, except that the default list starts at its Set Filter where that is the default filter. An index naming no filter selects the first.
defaultFilterParamsCopy Link
FilterWrapperParams
Params which will be passed to all filters

Suppressing Filters Copy Link

To remove a particular column / filter from the tool panel, set the column property suppressFiltersToolPanel to true.

suppressFiltersToolPanelCopy Link
boolean
default: false
Set to true if you do not want this column (filter) or group (filter group) to appear in the Filters Tool Panel.

Example: Configuring Filters Copy Link

The example below demonstrates configuring filters:

  • The Athlete column does not show a dropdown as it has filter: 'agSetColumnFilter' set.
  • The Age column shows all three grid-provided filter options by default.
  • The Country column is configured to show the Set Filter before the Text Filter.
  • The Year column is configured to show a custom filter component with the Set Filter.
  • The Date column has suppressFiltersToolPanel: true set, so it does not show in the tool panel.

Filters Tool Panel State Copy Link

When the grid initialises, the tool panel only shows active filters provided in the Initial State filter model. The tool panel can also be configured via initial state to show inactive filters, or change the order and expansion state. This is provided to the Side Bar state as a NewFiltersToolPanelState object:

filtersCopy Link
NewFiltersToolPanelFilterState[]
Ordered list of filters and their expansion state

Managing Tool Panel State Copy Link

The filter cards shown in the tool panel are part of the Side Bar state, which is separate from the filter model. Clearing the filter model with api.setFilterModel(null) therefore clears the filter values but leaves the (now inactive) cards in place.

To remove cards from the tool panel programmatically, see Choosing Filter Cards.

A saved layout can be restored by passing a previously captured sideBar state to api.setState. Pass the filter state too to restore each card's values as well as the cards themselves. See Grid State for the full getState and setState semantics.

Expand / Collapse Filter Cards Copy Link

The filter cards in the tool panel can be expanded and collapsed by invoking methods on the Filters Tool Panel instance:

expandFilterCardsCopy Link
Function
Expands the filter cards with the supplied colIds, or all filter cards if not supplied.
collapseFilterCardsCopy Link
Function
Collapses the filter cards with the supplied colIds, or all filter cards if not supplied.
// expands the 'age' and 'country' filter cards
gridApi.getToolPanelInstance('filters-new').expandFilterCards(['age', 'country']);

Only filters which already have a card in the tool panel are affected.

Choosing Filter Cards Copy Link

setFilterCards sets exactly which filter cards are shown in the tool panel, and in what order. Any column omitted from the list has its card removed, and its filter is cleared. Passing an empty array ([]) removes every card and clears their filters.

setFilterCardsCopy Link
Function
Shows a filter card for each of the supplied colIds, in that order. Every other card is removed and its filter cleared. Existing cards keep their expanded state; new cards are collapsed.
getStateCopy Link
Function
If saving and restoring state, this should return the current state
// shows only the 'athlete', 'country' and 'year' cards, in that order
gridApi.getToolPanelInstance('filters-new').setFilterCards(['athlete', 'country', 'year']);
  • Cards are shown in the order given.
  • Cards that already exist keep their expanded state. Cards that are added are collapsed, unlike when added using Add Filter in the tool panel, which adds them expanded.
  • Column IDs that do not match a column in the grid are skipped, and a warning is logged in development.

Example: Managing Filter Cards Copy Link

The example below starts with filters on Age and Country, and an inactive Athlete card:

  • Show Athlete, Country, Year calls setFilterCards(['athlete', 'country', 'year']). The Age card is removed and its filter is cleared. Country keeps its filter and expanded state, and Year is added collapsed.
  • Expand All and Collapse All call expandFilterCards() and collapseFilterCards().
  • Clear Filter Values calls api.setFilterModel(null). The rows are unfiltered, but the cards remain.
  • Remove Inactive uses getState to find the current cards, and passes the ones with a filter to setFilterCards.
  • Remove All calls setFilterCards([]). Every card is removed and the rows are unfiltered.
  • Save State captures the current grid state with api.getState().
  • Restore Saved State applies the saved filter and sideBar state, restoring both the cards and their values.
  • Restore Initial State applies the state the grid was created with.

Filter Instances Copy Link

The filters provided in the tool panel are the same instances as the filter in the column menu. This has the following implications:

  • Configuration relating to filters equally applies when the filters appear in the tool panel.
  • The filter behaves exactly as when it appears in the column menu. E.g. the Apply button will have the same meaning when used in the tool panel. Also the relationship with the Floating Filter (if active) will be the same.
  • If the filter is open on the tool panel and then the user subsequently opens the column menu, the tool panel filter will be closed. Because the filter is the same filter instance, it will only appear at one location at any given time.