Skip to content

Filter AST with Remote Data

Use a Filter AST with remote data to describe the filter in the grid and apply it to the complete dataset on your server. The server returns the filtered page and total count. This works with RevoGrid Pro’s remote pagination, as well as other server-owned data sources.

Open a column filter to build a Filter AST with the grouped editor. This demo enables openByDefault and predefinedFilters, so the editor opens directly with an empty condition for the selected column. Enter a value and apply the rule to send the tree to the simulated HTTP backend; the page and count update from the filtered results. The backend filters all 102 records before paging. The source tabs include the HTTP client and backend service. The simulated backend is demo infrastructure; use your own API in an application.

You can also edit a visible cell. Event Manager sends the edit to the same backend by user ID, and the grid reloads the active filter and page after the save. For example, filter Relationship to single, then change a visible value to relationship: the saved row leaves the filtered results and the count decreases. Valid relationship values are single, relationship, and complicated.

Source code
import { defineCustomElements } from '@revolist/revogrid/loader';
import {
AdvanceFilterPlugin,
EventManagerPlugin,
HistoryPlugin,
PaginationPlugin,
ColumnStretchPlugin,
RowOddPlugin,
} from '@revolist/revogrid-pro';
import { currentTheme } from '../composables/useRandomData';
import { createRemotePaginationColumns } from './pagination.remote.utils';
import { startRemotePagination } from './pagination.remote.bootstrap';
defineCustomElements();
export function load(parentSelector: string) {
const parent = document.querySelector(parentSelector);
if (!parent) throw new Error('Remote pagination container not found.');
const shell = document.createElement('section');
shell.className = 'pagination-remote-demo';
Object.assign(shell.style, {
minHeight: '0',
height: '360px',
display: 'flex',
flexDirection: 'column',
flex: '1 1 auto',
});
parent.appendChild(shell);
const lifetime = new AbortController();
const status = document.createElement('p');
status.setAttribute('role', 'status');
status.textContent = 'Starting demo backend…';
shell.appendChild(status);
let grid: HTMLRevoGridElement | undefined;
void startRemotePagination(lifetime.signal, () => grid)
.then(({ pagination, eventManager }) => {
if (lifetime.signal.aborted) return;
grid = document.createElement('revo-grid');
grid.className = 'overflow-hidden cell-border';
grid.style.cssText = 'height: 100%; min-height: 0; flex: 1 1 0;';
grid.columns = createRemotePaginationColumns();
const filterConfig = {
predefinedFilters: true,
groupedFilter: { remote: true, openByDefault: true },
};
grid.filter = filterConfig;
grid.addEventListener('externalediterror', () => {
status.setAttribute('role', 'alert');
status.textContent = 'Could not save changes.';
shell.appendChild(status);
});
grid.stretch = 'all';
grid.pagination = pagination;
grid.eventManager = eventManager;
grid.plugins = [
PaginationPlugin,
AdvanceFilterPlugin,
EventManagerPlugin,
HistoryPlugin,
ColumnStretchPlugin,
RowOddPlugin,
];
grid.theme = currentTheme().isDark() ? 'darkMaterial' : 'material';
grid.hideAttribution = true;
shell.appendChild(grid);
grid.source = [];
status.remove();
})
.catch((error) => {
if (lifetime.signal.aborted) return;
status.setAttribute('role', 'alert');
status.textContent = error.message;
});
return () => {
lifetime.abort();
grid?.remove();
shell.remove();
};
}

Register AdvanceFilterPlugin and PaginationPlugin. The pagination plugin intercepts filter changes, resets to the first page, and passes the AST and execution context to loadData. Send those values along with the page request:

import { AdvanceFilterPlugin, PaginationPlugin } from '@revolist/revogrid-pro';
grid.plugins = [PaginationPlugin, AdvanceFilterPlugin];
grid.filter = {
predefinedFilters: true,
groupedFilter: { remote: true, openByDefault: true },
};
grid.pagination = {
itemsPerPage: 10,
initialPage: 0,
total: 0,
query: { staleTime: 30_000 },
loadData: async (
skip,
take,
order,
_filter,
_filterItems,
_quickFilter,
_temporalContext,
filterAst,
executionContext,
context,
) => {
const response = await fetch('/api/users/search', {
method: 'POST',
headers: { 'content-type': 'application/json' },
signal: context?.signal,
body: JSON.stringify({ skip, take, order, filterAst, executionContext }),
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
return response.json(); // { data: User[], count: number }
},
};

Pagination uses the built-in Query engine for remote reads. It caches filtered pages and retries transient read failures. For more options, see Loading and Caching Server Data.

When the filter is cleared, filterAst can be absent. The server should treat that as an unfiltered request. Apply the filter and sort before slicing the requested page, and return the count after filtering but before paging. Send the execution context so relative dates and blank-value policies can be evaluated consistently. If your application also enables quick search or separate temporal filter state, forward and implement those inputs as needed.

Validate the tree and allow-list fields and operators on the server. Translate it to your backend’s query language using parameterized queries; RevoGrid does not automatically generate SQL, REST, or GraphQL. The live example uses validateFilterAst, collectFilterAstFields, and compileFilterAst against an in-memory dataset.

For a custom remote datasource without PaginationPlugin, configure the advanced filter with external: true or cancel beforefilterapply, send its AST and execution context to your service, and replace the grid rows with the result. See events and remote ownership for the event details and remote pagination for the complete loader contract.

The live example registers EventManagerPlugin and configures eventManager.externalEdit. Its getRowKey uses the stable user ID, and apply sends candidate IDs, row keys, fields, old values and proposed values to the backend. The backend returns one changed, unchanged or rejected result for each candidate. After a successful write, the client runs the refresh returned by PaginationPlugin.captureMutationRefresh(). This invalidates the cached pages and reloads the current filter, sort and page. See the HTTP client and Backend service source tabs for the complete implementation and the external-editing guide for the Event Manager contract.

With the grid focused, use its Undo or Redo shortcut to replay an edit after changing pages or filters. The demo sends a separate history command by stable row ID, then refreshes the current page after the mock backend commits. See replay outside the loaded view for the production receipt contract.