#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.
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.
Columns are not filterable by default. Set filterable: true on the
columns (or in columnDefaults, as above) — filters on non-filterable columns
are ignored.
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.
#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. Setfilters.showFilterUIForColumnstotrueorfalseto 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 type | Default for | Operators | Editor |
|---|---|---|---|
text | text | CONTAINS, NOT_CONTAINS, EQ, NEQ, STARTS_WITH, ENDS_WITH, IS_BLANK, IS_NOT_BLANK | text input |
number | number | EQ, NEQ, GT, GTE, LT, LTE, IS_BLANK, IS_NOT_BLANK | number input |
date | date | EQ, NEQ, GT, GTE, LT, LTE, IS_BLANK, IS_NOT_BLANK | date input with a popover calendar |
boolean | boolean | EQ | all / yes / no toggle |
array | array | IN, NOT_IN, IS_BLANK, IS_NOT_BLANK | multi-select picker |
singleValue | — | EQ, NEQ, IS_BLANK, IS_NOT_BLANK | single-select picker |
multiValue | — | IN, NOT_IN, IS_BLANK, IS_NOT_BLANK | multi-select picker |
values | — | all of the picker operators above | single- 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:
column.filterType(or a column override in the view),dataTypeDefaults[column.dataType].filterType,- the built-in type named after the column's
dataType.
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.
const customFilterTypeState: AdaptableUserState = {
globalEntities: {
filterTypes: {
salary: {
label: 'Salary',
extends: 'number',
defaultOperator: 'AT_LEAST',
operators: [
{
name: 'AT_LEAST',
label: 'At least',
icon: () => <>≥</>,
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'seditoris used otherwise).fn— the local filtering logic, called for every row when the grid filters on the client. It receivescurrentValue,filterValue, the rowdataand thecolumnId. Leave it out for operators that only make sense on the server.label,iconanddefaultFilterValue.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)'] },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.
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.
#Custom filter editors
An editor is a React component rendered in the filter row. Inside it,
useColumnFilterEditor() returns everything needed to read and write the
filter:
import {
FilterEditorShell,
filterEditorControlClassName,
useColumnFilterEditor,
} from '@adaptabletools/datagrid-react';
function MinSalaryEditor() {
const { ariaLabel, value, setValue, disabled } = useColumnFilterEditor();
return (
<FilterEditorShell>
<input
aria-label={ariaLabel}
className={filterEditorControlClassName}
disabled={disabled}
type="range"
min={70000}
max={210000}
value={value ?? 70000}
onChange={(event) => setValue(Number(event.target.value))}
/>
</FilterEditorShell>
);
}setValueapplies the value after a short delay (for typing);commitValueapplies it immediately (for pickers, calendars, toggles).clearValueremoves the filter.FilterEditorShelldraws the standard chrome: the operator switch on the left and the clear button on the right. PassshowOperator={false}orclearable={false}to drop either;actionsadds controls before the clear button.filterType,operator,operatorNameandadaptableColumndescribe the current filter;operatorslists the operators the column offers andsetOperator(name)switches to one of them.
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.
#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:
column.filterValues,- the filter type's
values, - the data source's
filterValuesloader — thefilterValuesprop ofAdaptable.DataSource(or thefilterValuesprop of the Provider), or thefilterValuescarried by the data function (createTdgpDataSourceprovides one), - 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:
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:
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,
useColumnFilterValues({ columnId }) loads the values (with search and paging)
from whichever provider applies.
#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, the useColumnFilters hook reads and writes the current view's column
filters:
import { useColumnFilters } from '@adaptabletools/datagrid-react';
function MyFilterChips() {
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
} = useColumnFilters();
// ...
}Imperatively, adaptableApi.filterApi offers setColumnFilters,
clearColumnFilters, setColumnFilterPaused and setAllColumnFiltersPaused.