Core Features

Advanced Features

JavaScript Data GridAdvanced Filter - Filter Model / API

Version 36.2.0
Enterprise

The state of the Advanced Filter can be read as an Advanced Filter Model, and applied again later by setting that model back. This allows the filter to be saved and restored, for example across page reloads or between users, or to be set programmatically without typing an expression.

Advanced Filter Model Copy Link

The Advanced Filter model describes the current state of the Advanced Filter. This is represented by an AdvancedFilterModel, which is either a ColumnAdvancedFilterModel for a single condition, or a JoinAdvancedFilterModel for multiple conditions:

filterTypeCopy Link
'join'
'join'
'AND' | 'OR'
How the conditions are joined together
conditionsCopy Link
AdvancedFilterModel[]
The filter conditions that are joined by the type

For example, the following Advanced Filter would be represented by the following model:

([Age] > 23 OR [Sport] ends with "ing") AND [Country] is any of ["Australia", "Italy"]

const advancedFilterModel = {
    filterType: 'join',
    type: 'AND',
    conditions: [
      {
        filterType: 'join',
        type: 'OR',
        conditions: [
          {
            filterType: 'number',
            colId: 'age',
            type: 'greaterThan',
            filter: 23,
          },
          {
            filterType: 'text',
            colId: 'sport',
            type: 'endsWith',
            filter: 'ing',
          }
        ]
      },
      {
        filterType: 'set',
        colId: 'country',
        type: 'isAnyOf',
        values: ['Australia', 'Italy'],
      }
    ]
};

A condition using a Custom Filter Option stores the option's displayKey in type.

Saving and Restoring the Advanced Filter Copy Link

The Advanced Filter Model can be retrieved via the API method getAdvancedFilterModel, and set via the API method setAdvancedFilterModel.

getAdvancedFilterModelCopy Link
Function
Get the state of the Advanced Filter. Used for saving Advanced Filter state
setAdvancedFilterModelCopy Link
Function
Set the state of the Advanced Filter or used for restoring Advanced Filter state. If inferring cell data types, and row data is initially empty or yet to be set, the filter model will be applied asynchronously after row data is added. To always perform this synchronously, set cellDataType = false on the default column definition, or provide cell data types for every column.

The Advanced Filter Model can be saved and restored as part of Grid State.

The Advanced Filter Model and API methods are demonstrated in the following example:

  • Clicking Save Advanced Filter Model will save the current Advanced Filter.
  • Clicking Restore Saved Advanced Filter Model will restore the previously saved Advanced Filter.
  • Clicking Set Custom Advanced Filter Model will set [Gold] >= 1.
  • Clicking Clear Advanced Filter will clear the current Advanced Filter.