Adaptable

#Column Filters

Column filters hide the rows that don't match a condition on a single column. They are the filters users type into the filter row under the column headers.

Column filters are part of the view: each table view lists them in filters.columns, as AdaptableQL expressions — one predicate per column.

Column filters in a view
const state: AdaptableUserState = {
  globalEntities: {
    columnDefaults: { filterable: true },
    availableColumns,
  },
  view: {
    currentViewId: 'default',
    views: [
      {
        id: 'default',
        label: 'Filtered developers',
        filters: {
          columns: ['[salary] > 120000', '[preferredLanguage] CONTAINS "Script"'],
        },
      },
    ],
  },
};

Adaptable parses each expression to find out which column it filters, and shows the operator and value in that column's filter row.

Warning

Columns are not filterable by default. Set filterable: true on the columns (or in columnDefaults, as above) — filters on non-filterable columns are ignored.

#
Defining column filters

The view filters the salary column ([salary] > 120000) and the preferredLanguage column (CONTAINS "Script"). Change the operator or value in the filter row, or type into another column's filter.

open
loading demo…

#Rules for column filters

  • Each expression references only one column, compared with a value — like [price] > 10.
  • A column has at most one filter; when two expressions target the same column, the last one wins.
  • The filter row is shown when the view has filters.columns (even an empty array) and at least one column is filterable. Set filters.showFilterUIForColumns to true or false to decide it explicitly.
  • Column filters apply to table views only.

To filter on several columns at once — or several conditions on the same column — use the grid filter. Both work together: a row is shown only when it passes the grid filter and every column filter.

#Pausing filters

A paused filter stays in the view (and in the filter row) but doesn't hide any row. filters.paused.columns is either true (pause every column filter) or a record of the paused column ids:

filters: {
  columns: ['[salary] > 120000', '[country] = "Japan"'],
  paused: { columns: { country: true } },
},

#Filter types

Every column is filtered through a filter type. A filter type decides:

  • which operators the column filter offers (EQ, CONTAINS, IN, …),
  • how each operator filters locally, when the grid filters on the client,
  • which editor the filter row renders.

There is a built-in filter type for every data type, plus three pickers:

Filter typeDefault forOperatorsEditor
texttextCONTAINS, NOT_CONTAINS, EQ, NEQ, STARTS_WITH, ENDS_WITH, IS_BLANK, IS_NOT_BLANKtext input
numbernumberEQ, NEQ, GT, GTE, LT, LTE, IS_BLANK, IS_NOT_BLANKnumber input
datedateEQ, NEQ, GT, GTE, LT, LTE, IS_BLANK, IS_NOT_BLANKdate input with a popover calendar
booleanbooleanEQall / yes / no toggle
arrayarrayIN, NOT_IN, IS_BLANK, IS_NOT_BLANKmulti-select picker
singleValue—EQ, NEQ, IS_BLANK, IS_NOT_BLANKsingle-select picker
multiValue—IN, NOT_IN, IS_BLANK, IS_NOT_BLANKmulti-select picker
values—all of the picker operators abovesingle- or multi-select, decided by operator

The picker types let users choose from the values in the column (see Filter values for where those come from). Use singleValue or multiValue when the cardinality is fixed, and values when users should be able to switch between EQ-style and IN-style operators.

When the grid filters on the client, the built-in text and picker operators compare case-insensitively, and date operators compare by day.

#Choosing the filter type of a column

The filter type of a column is resolved in this order:

  1. column.filterType (or a column override in the view),
  2. dataTypeDefaults[column.dataType].filterType,
  3. the built-in type named after the column's dataType.
Assigning filter types
const filterTypeState: AdaptableUserState = {
  globalEntities: {
    availableColumns: {
      preferredLanguage: {
        field: 'preferredLanguage',
        dataType: 'text',
        filterType: 'values', // pick from the values in the column
      },
      tags: {
        field: 'tags',
        dataType: 'array',
        filterType: 'multiValue',
      },
      salary: { field: 'salary', dataType: 'number' },
    },
    dataTypeDefaults: {
      number: { filterType: 'salary' }, // every number column, unless it says otherwise
    },
  },
  view: {
    currentViewId: 'default',
    views: [{ id: 'default', label: 'Default' }],
  },
};

column.filterOperators further restricts the operators a column offers, by operator name — for example filterOperators: ['STARTS_WITH', 'EQ'].

#Defining your own filter types

Define filter types in globalEntities.filterTypes (or in a view's privateEntities.filterTypes). Most custom types start from a built-in one with extends, which inherits its operators, editor and empty values. The operators of the new type are merged by name: existing operators are overridden, new ones appended.

A number filter type with an extra operator
// the operator icon is a component too
@Component({ selector: 'at-least-icon', template: `≥` })
class AtLeastIcon {}

const customFilterTypeState: AdaptableUserState = {
  globalEntities: {
    filterTypes: {
      salary: {
        label: 'Salary',
        extends: 'number',
        defaultOperator: 'AT_LEAST',
        operators: [
          {
            name: 'AT_LEAST',
            label: 'At least',
            icon: AtLeastIcon,
            editor: MinSalaryEditor,
            defaultFilterValue: 70000,
            fn: ({ currentValue, filterValue }) => currentValue >= filterValue,
          },
        ],
      },
    },
  },
  view: {
    currentViewId: 'default',
    views: [{ id: 'default', label: 'Default' }],
  },
};

Each operator has:

  • editor — an editor for this operator only (the filter type's editor is used otherwise).
  • fn — the local filtering logic, called for every row when the grid filters on the client. It receives currentValue, filterValue, the row data and the columnId. Leave it out for operators that only make sense on the server.
  • label, icon and defaultFilterValue.
  • name — how the operator is written in the AQL column filter. Built-in AQL operators (EQ, GT, CONTAINS, IN, …) produce [salary] > 120000; any other name is written as a function call, AT_LEAST([salary], 120000).

A view then uses the custom operator like any other:

filters: { columns: ['AT_LEAST([salary], 120000)'] },
Note

Redefining a built-in id is a partial override: filterTypes: { number: { editor: MyNumberEditor } } swaps the editor of every number column and keeps the built-in number operators. The built-in types are also exported as defaultFilterTypes, so you can spread one into your own.

#
A custom filter type

The salary column uses a salary filter type that extends number with an AT_LEAST operator and a slider editor. preferredLanguage uses the built-in values picker, and country offers only STARTS_WITH and EQ.

open
loading demo…

#Custom filter editors

An editor is an Angular component rendered in the filter row. Inside it, injectColumnFilterEditor() returns everything needed to read and write the filter, as one signal of an object: call it in a field initializer and read it as editor(), in the class and in the template.

A filter editor
import {
  FilterEditorShell,
  filterEditorControlClassName,
  injectColumnFilterEditor,
} from '@adaptabletools/datagrid-angular';

@Component({
  selector: 'min-salary-editor',
  imports: [FilterEditorShell],
  template: `
    <div adaptableFilterEditorShell>
      <input
        [attr.aria-label]="editor().ariaLabel"
        [class]="controlClassName"
        [disabled]="editor().disabled"
        type="range"
        min="70000"
        max="210000"
        [value]="editor().value ?? 70000"
        (input)="editor().setValue(+$any($event.target).value)"
      />
    </div>
  `,
})
class MinSalaryEditor {
  // a signal: `editor()` is always the current filter
  protected readonly editor = injectColumnFilterEditor();
  protected readonly controlClassName = filterEditorControlClassName;
}
  • setValue applies the value after a short delay (for typing); commitValue applies it immediately (for pickers, calendars, toggles). clearValue removes the filter.
  • FilterEditorShell draws the standard chrome: the operator switch on the left and the clear button on the right. It is the adaptableFilterEditorShell attribute of a div, with the control as its content. Bind [showOperator]="false" or [clearable]="false" to drop either; [actions] (a Renderable, such as an <ng-template>) adds controls before the clear button.
  • filterType, operator, operatorName and adaptableColumn describe the current filter; operators lists the operators the column offers and setOperator(name) switches to one of them.

The operator icon is a component as well (or a template).

Besides the filter type and operator editor, a single column can use its own editor via components.FilterEditor in its column config.

The built-in editors — TextFilterEditor, NumberFilterEditor, DateFilterEditor, BooleanFilterEditor, ValuesFilterEditor, SingleValueFilterEditor, MultiValueFilterEditor — are exported too, so an editor can wrap one of them or fall back to it for some operators.

Like the shell, each of them is an attribute of a div in a template: <div adaptableNumberFilterEditor></div>, <div adaptableValuesFilterEditor></div>, …

#Filter values

The picker types (singleValue, multiValue, values, array and anything extending them) need a list of values to choose from. The values are resolved in this order:

  1. column.filterValues,
  2. the filter type's values,
  3. the data source's filterValues loader — the filterValues input of <adaptable-data-source> (or the filterValues input of <adaptable-provider>), or the filterValues carried by the data function (createTdgpDataSource provides one),
  4. in client mode, the distinct values of the loaded rows.

A provider is a static list, a list of { value, label, count, icon } options, or a loader function — sync or async:

Static and async filter values
const filterValuesState: AdaptableUserState = {
  globalEntities: {
    availableColumns: {
      country: {
        field: 'country',
        dataType: 'text',
        filterType: 'values',
        filterValues: ['France', 'Japan', 'USA'],
      },
      preferredLanguage: {
        field: 'preferredLanguage',
        dataType: 'text',
        filterType: 'multiValue',
        filterValues: async ({ search, start, limit, signal }) => {
          const response = await fetch(`/api/languages?q=${search}&start=${start}&limit=${limit}`, {
            signal,
          });
          const { values, totalCount } = await response.json();
          // values: [{ value: 'Go', count: 3 }, ...]
          return { values, totalCount };
        },
      },
    },
  },
  view: {
    currentViewId: 'default',
    views: [{ id: 'default', label: 'Default' }],
  },
};

The loader receives search (what the user typed), a paging window (start, limit), the currently selectedValues, and an AbortSignal. Return totalCount to let the picker page through more values; without it, the returned list is taken as complete.

Wrap the provider in an options object to tune the picker:

Filter values options
filterValues: {
  values: loadValues,
  pageSize: 50, // values per page, default 100
  cascade: true, // narrow by the other columns' filters (the loader gets `cascadeFilter` as AQL)
  withCounts: true, // ask for facet counts, default true
  refreshOnOpen: false, // cache the values until the column filters change
  formatValue: (value, column) => `${value} developers`,
},

The same options can be given on a filter type (filterTypes.myPicker.values), so all columns using it share the provider. For a custom picker editor, injectColumnFilterValues loads the values (with search and paging) from whichever provider applies. It takes a function that returns its options (it re-reads them when the signals they read change), and returns a signal: injectColumnFilterValues(() => ({ columnId: this.editor().columnId })).

#Managing column filters

Users edit column filters in the filter row, and on the Filter page of the settings panel, which lists the current view's column filters next to its grid filter. There they can pause, remove and add filters, edit them in the full expression editor, save one as a named query, or apply a named query as a column filter.

In code, injectColumnFilters() reads and writes the current view's column filters. Call it in a component rendered inside <adaptable-provider>; it returns one signal of an object:

import { injectColumnFilters } from '@adaptabletools/datagrid-angular';

// a component rendered inside <adaptable-provider>
@Component({ selector: 'my-filter-chips', template: `<!-- ... -->` })
class MyFilterChips {
  // a signal: read it where you use it, so it is always current
  private readonly columnFiltersModel = injectColumnFilters();

  onSomeEvent() {
    const {
      columnFilters, // [{ expression, columnId, columnLabel, isPaused, error? }]
      addColumnFilter, // (expression) => void
      setColumnFilter, // (index, expression) => void — '' removes it
      removeColumnFilter, // (index) => void
      clearColumnFilters,
      setPaused, // (columnId, paused) => void
      setAllPaused, // (paused) => void
      getColumnFilterError, // (expression) => string | undefined
    } = this.columnFiltersModel();

    // ...
  }
}

Imperatively, adaptableApi.filterApi offers setColumnFilters, clearColumnFilters, setColumnFilterPaused and setAllColumnFiltersPaused.