#Grid Filter
The grid filter is a single AdaptableQL boolean expression that
every row must satisfy to be shown. Unlike a column filter,
it can reference any number of columns, combine conditions with AND /
OR, and put several conditions on the same column.
The grid filter is part of the view — set it in the table view's
filters.grid:
const state: AdaptableUserState = {
view: {
currentViewId: 'typescript-or-senior',
views: [
{
id: 'typescript-or-senior',
label: 'TypeScript or salary > 150k',
filters: { grid: '[preferredLanguage] = "TypeScript" OR [salary] > 150000' },
},
],
},
};The grid filter and the column filters work together: a row is shown only when it passes the grid filter and every column filter. Grid filters apply to table views only — pivot views have none.
The expression may use aggregations, which are computed over all rows — so
[salary] > AVG{[salary]} keeps the rows with an above-average salary.
Two views, each with its own grid filter. Switch views in the view picker and watch the row count; edit the expression in the grid filter input of the dashboard.
#Pausing the grid filter
A paused grid filter stays in the view but doesn't hide any row. Pause it with
filters.paused.grid: true, from the settings panel, or with
adaptableApi.filterApi.setGridFilterPaused(true).
#Named queries
A named query is a reusable AdaptableQL expression, stored in the
namedQuery state slice and referenced from other expressions as
QUERY("name") (names are case-insensitive). A grid filter can be a named
query, or combine one with other conditions:
const namedQueryState: AdaptableUserState = {
namedQuery: {
'high-earners': {
name: 'HighEarners',
expression: '[salary] > 120000',
description: 'Developers earning more than 120k',
},
},
view: {
currentViewId: 'default',
views: [
{
id: 'default',
label: 'High earners outside the USA',
filters: { grid: 'QUERY("HighEarners") AND [country] != "USA"' },
},
],
},
};When the named query changes, every grid filter that references it re-runs. Named queries are evaluated per row, so they can't contain aggregations.
The grid filter references the HighEarners named query. Open the settings
panel, go to Named Queries and change the salary threshold — the grid
re-filters.
#Editing the grid filter
The grid-filter dashboard widget shows the current view's
grid filter as an inline expression input.
The Filter page of the settings panel edits the grid
filter and the column filters of the current view. For
the grid filter, users can edit the expression inline or in the full editor,
pause, resume or clear it, save it as a named query (the filter then
becomes a QUERY("name") reference, so editing the query updates the filter),
or apply an existing named query.
The page is also available standalone as Adaptable.UI.ViewGridFilterEditor,
and you can replace it in the settings panel with your own component through
components.ViewGridFilterEditor on the Provider.
#Building your own filter UI
The useGridFilter hook reads and writes the current view's grid filter:
import { useGridFilter } from '@adaptabletools/datagrid-react';
function MyGridFilter() {
const {
isTableView, // grid filters apply to table views only
gridFilter, // the current expression, '' when none
setGridFilter, // (expression | undefined) => void — '' removes it
clearGridFilter,
isPaused,
setPaused, // (paused) => void
isValidGridFilter, // (expression) => boolean
} = useGridFilter();
// ...
}The input above the grid is built with useGridFilter. Type an expression such
as [country] = "Japan" OR [salary] < 80000 and press Apply — invalid
expressions are outlined in red. Pause keeps the filter but shows every row.
Imperatively, use adaptableApi.filterApi.setGridFilter(expression). You can
also drive the grid filter through controlled state: pass
state and onStateChange to the Provider and write filters.grid of the
current view yourself.