Skip to content

Filter AST Side Panel

The grouped Filter AST editor is not limited to a column popup. Mount the same editor in a persistent side panel, drawer, or inspector and keep the grid plugin responsible for configured fields and operators, validation, preview, and applying the canonical tree.

Source code
import { applyControlPresentation } from '@revolist/ui';
import type {
FilterAstChangeEventDetail,
FilterAstEditorHandle,
} from '@revolist/revogrid-pro';
import { defineCustomElements } from '@revolist/revogrid/loader';
import {
createFilterAstSidePanelRows,
filterAstSidePanelColumns,
filterAstSidePanelConfig,
filterAstSidePanelEditorOptions,
filterAstSidePanelPlugins,
getFilterAstSidePanelVisibleCount,
getSidePanelFilterPlugin,
type SupportTicket,
} from './FilterAstSidePanel.shared';
import './filter-ast-side-panel.scss';
defineCustomElements();
export function load(parentSelector: string, inputRows?: SupportTicket[]) {
const parent = document.querySelector(parentSelector);
if (!parent) throw new Error(`Could not find ${parentSelector}.`);
const rows = inputRows?.length ? inputRows : createFilterAstSidePanelRows();
const root = document.createElement('section');
root.className = 'filter-ast-side-panel';
root.dataset.testid = 'filter-ast-side-panel';
root.innerHTML = `
<aside class="filter-ast-side-panel__rail" aria-label="Filter tree editor">
<div data-editor-host class="filter-ast-side-panel__editor-host"></div>
</aside>
<main class="filter-ast-side-panel__content">
<div class="filter-ast-side-panel__result">
<div><h3>Support queue</h3><p>The side panel and grouped dialog use the same canonical editor.</p></div>
<span data-count class="filter-ast-side-panel__count" data-testid="filter-ast-side-panel-count"></span>
</div>
<div data-grid></div>
<details class="filter-ast-side-panel__ast">
<summary>View the effective Filter AST</summary>
<pre data-ast data-testid="filter-ast-side-panel-json">undefined</pre>
</details>
</main>`;
applyControlPresentation(root);
const grid = document.createElement('revo-grid');
grid.className =
'filter-ast-side-panel__grid demo-preview-content-sized-grid cell-border';
grid.theme = 'compact';
grid.columns = filterAstSidePanelColumns;
grid.plugins = filterAstSidePanelPlugins;
grid.filter = filterAstSidePanelConfig;
grid.stretch = 'last';
grid.hideAttribution = true;
root.querySelector<HTMLElement>('[data-grid]')!.replaceWith(grid);
const editorHost = root.querySelector<HTMLElement>('[data-editor-host]')!;
const count = root.querySelector<HTMLElement>('[data-count]')!;
const ast = root.querySelector<HTMLElement>('[data-ast]')!;
let editor: FilterAstEditorHandle | undefined;
let initializing = false;
let destroyed = false;
const updateCount = async () => {
count.textContent = `${await getFilterAstSidePanelVisibleCount(grid)} of ${rows.length} tickets`;
};
const onFilterAstChange = (event: Event) => {
const detail = (event as CustomEvent<FilterAstChangeEventDetail>).detail;
ast.textContent = JSON.stringify(detail.filterAst, null, 2) ?? 'undefined';
};
const initialize = async () => {
if (destroyed || editor || initializing) return;
initializing = true;
try {
await grid.componentOnReady();
if (destroyed) return;
const plugin = await getSidePanelFilterPlugin(grid);
if (destroyed || editor) return;
editor = plugin.mountFilterAstEditor(
editorHost,
filterAstSidePanelEditorOptions,
);
ast.textContent =
JSON.stringify(plugin.getFilterAst(), null, 2) ?? 'undefined';
grid.addEventListener('filterastchange', onFilterAstChange);
grid.addEventListener('afterfilterapply', updateCount);
await updateCount();
} finally {
initializing = false;
}
};
grid.addEventListener('aftergridinit', initialize, { once: true });
parent.append(root);
grid.source = rows;
void customElements.whenDefined('revo-grid').then(initialize);
return () => {
destroyed = true;
editor?.destroy();
grid.removeEventListener('aftergridinit', initialize);
grid.removeEventListener('filterastchange', onFilterAstChange);
grid.removeEventListener('afterfilterapply', updateCount);
root.remove();
};
}

Resolve the installed plugin after the grid initializes, mount the editor into a connected host, and destroy the returned handle with your framework component:

const plugin = (await grid.getPlugins()).find(
(item) => item instanceof AdvanceFilterPlugin,
);
const editor = plugin.mountFilterAstEditor(editorHost, {
preset: 'fixed-list',
conditionSlots: initialAst.children,
});
// Component teardown
editor.destroy();

When the mounted editor is the only filtering surface, set filter.columnFilterButton to false. This removes the compact button and its hover/focus layout reservation from every column header while leaving filtering, the active AST, and the mounted editor enabled.

The fixed-list preset accepts a flat root AND tree of predeclared conditions. Pass those definitions as conditionSlots so their field and predicate remain visible after clearing. Fields stay fixed, while each predicate badge can select another operator supported by that column. Each active row has a compact, accessible clear action. Clearing removes its value from the draft and omits the condition from the canonical AST; entering or selecting a new valid value applies it again. A cleared valueless predicate, such as “VIP is false,” makes its predicate badge the explicit Apply action. Clear all clears every slot, applies undefined, and restores every grid row without removing the predefined controls.

Choose reusable value controls in the column configuration. The example renders Priority’s compatible scalar numeric predicates with the shared single-value slider without adding editor configuration at the mount site:

{
name: 'Priority',
prop: 'priority',
filter: 'number',
filterAstValueEditor: { kind: 'slider', min: 1, max: 5, step: 1 },
}

Omitted slider bounds are derived from the grid source. Use mount-level valueEditors only when a particular surface needs a field- or field/operator-specific override; those overrides take precedence over the column default without changing the canonical predicate.

The preset keeps each field fixed as a plain anchor, presents each read-only operator phrase as a compact theme-aware badge, exposes only the configured value editor, omits placeholder boxes for operators that need no value, and applies effective changes after a short debounce. Builder chrome, grouping, add/remove/reorder actions, mode switch, and footer are intentionally absent. editor.reset(ast) remains the explicit synchronization boundary: it maps conditions in the supplied effective AST back onto the stable slots and clears omitted slots. Successful changes continue through the existing filterastchange event.

Use the default builder preset for the complete nested AND/OR/NOT rule builder, or read-only to inspect a tree without mutation. Nested configuration can override structure, capabilities, presentation, workflow, and interaction independently; incompatible flat trees are rejected rather than silently flattened.

This surface reuses the grouped editor’s configured operators, selection sources, structured filter mounts, localization, validation, preview, and canonical apply path. It does not embed every complete classic per-column popup; reusable controls converge through the same lower-level filter contracts.

The mounted editor belongs to its application host and inherits the public --rv-filter-ast-editor-* variables defined there. Use surface-bg, surface-color, control-bg, text-color, and the corresponding control-border, divider, active-*, or muted-color variables to align it with the surrounding application theme. Unset variables use the editor’s standalone defaults.

For the underlying model and business case, read What Is a Filter AST?. For the complete API and operator contract, continue with Canonical Filter AST.