Skip to content

FilteringPlugin

Filtering Plugin for tbw-grid

Adds column header filters with text search, dropdown options, and custom filter panels. Supports both local filtering for small datasets and async handlers for server-side filtering on large datasets.

import { FilteringPlugin } from '@toolbox-web/grid/plugins/filtering';
PropertyTypeDescription
filterablebooleanEnable filtering for this column
filterType'text' | 'select' | 'number' | 'date'Filter UI type
filterOptionsunknown[]Predefined options for select filters
PropertyDefaultDescription
--tbw-filter-panel-bgvar(--tbw-color-panel-bg)Panel background
--tbw-filter-panel-fgvar(--tbw-color-fg)Panel text color
--tbw-filter-panel-bordervar(--tbw-color-border)Panel border
--tbw-filter-active-colorvar(--tbw-color-accent)Active filter indicator
--tbw-filter-input-bgvar(--tbw-color-bg)Input background
--tbw-filter-input-focusvar(--tbw-color-accent)Input focus border
OptionTypeDescription
debounceMs?numberDebounce delay in milliseconds for the search input inside the default filter panel. Controls how long the panel waits after the user stops typing before re-filtering the unique values list.
caseSensitive?booleanWhether text-based filtering comparisons are case-sensitive.
trimInput?booleanWhether to trim leading/trailing whitespace from filter input values before applying them.
useWorker?booleanWhether to offload filtering to a Web Worker for large datasets.
filterPanelRenderer?FilterPanelRendererCustom filter panel renderer that replaces the built-in panel content for all columns (unless you return undefined for specific columns to fall through to the next level).
trackColumnState?booleanWhether filter state should be included in column state persistence.
valuesHandler?FilterValuesHandlerAsync handler for fetching unique filter values from a server.
filterHandler?FilterHandler<TRow>Async handler for delegating filtering to a server.
import { queryGrid } from '@toolbox-web/grid';
import { FilteringPlugin } from '@toolbox-web/grid/plugins/filtering';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Name', filterable: true },
{ field: 'status', header: 'Status', filterable: true, filterType: 'select' },
{ field: 'email', header: 'Email', filterable: true },
],
plugins: [new FilteringPlugin({ debounceMs: 300 })],
};
grid.rows = data;
When a column defines a `format` function, the built-in set filter panel
displays formatted labels instead of raw values. Search within the panel
also matches against the formatted text.
```ts
grid.gridConfig = {
columns: [
{
field: 'price',
filterable: true,
format: (value) => `$${Number(value).toFixed(2)}`,
// Filter checkboxes show "$9.99" instead of "9.99"
},
],
plugins: [new FilteringPlugin()],
};
### Server-Side Filtering with Async Handlers
```ts
new FilteringPlugin({
// Fetch unique values from server for filter dropdown
valuesHandler: async (field, column) => {
const response = await fetch(`/api/distinct-values?field=${field}`);
return response.json();
},
// Apply filters on the server
filterHandler: async (filters, currentRows) => {
const response = await fetch('/api/data', {
method: 'POST',
body: JSON.stringify({ filters }),
});
return response.json();
},
});

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Set a filter on a specific field. Pass null to remove the filter.

setFilter(field: string, filter: Omit<FilterModel, "field"> | null, options: object): void
NameTypeDescription
fieldstring
filterOmit<FilterModel, field> | unknown
optionsobject{ silent: true } applies the filter without emitting filter-change

Get the current filter for a field.

getFilter(field: string): FilterModel | undefined
NameTypeDescription
fieldstring

Get all active filters.

getFilters(): FilterModel[]

Alias for getFilters() to match functional API naming.

getFilterModel(): FilterModel[]

Set filters from an array (replaces all existing filters).

setFilterModel(filters: FilterModel[], options: object): void
NameTypeDescription
filtersFilterModel[]
optionsobject{ silent: true } applies filters without emitting filter-change

Clear all filters.

clearAllFilters(options: object): void
NameTypeDescription
optionsobject{ silent: true } clears filters without emitting filter-change

Clear filter for a specific field.

clearFieldFilter(field: string, options: object): void
NameTypeDescription
fieldstring
optionsobject{ silent: true } clears filter without emitting filter-change

Check if a field has an active filter.

isFieldFiltered(field: string): boolean
NameTypeDescription
fieldstring

Get the count of filtered rows (from cache).

getFilteredRowCount(): number

Get all active filters (alias for getFilters).

getActiveFilters(): FilterModel[]

Get unique values for a field (for set filter dropdowns).

Prefers sourceRows (raw user input). When the user does not own the data (e.g. ServerSidePlugin is active and sourceRows is empty), falls back to the processed rows with placeholder/loading rows excluded so users get filter values for whatever has been loaded so far.

When a column has filterValue, individual extracted values are returned.

getUniqueValues(field: string): unknown[]
NameTypeDescription
fieldstring

Get set filters whose exclusion/inclusion list no longer matches any values in the current data, effectively selecting zero rows.

  • notIn: stale when every current unique value is in the exclusion list (selected count = 0)
  • in: stale when none of the included values exist in the current data
getStaleFilters(): FilterModel[]

Get the current blank mode for a field.

  • 'all' — no blank filter active
  • 'blanksOnly'blank operator active
  • 'nonBlanksOnly'notBlank operator active
getBlankMode(field: string): BlankMode
NameTypeDescription
fieldstring

Toggle blank filter mode for a field.

Handles transitions:

  • 'all' → clears the filter entirely
  • 'blanksOnly' → sets blank operator, stashing any active filter in valueTo
  • 'nonBlanksOnly' → sets notBlank operator, stashing any active filter in valueTo

When switching back to 'all', the stashed filter (if any) is restored.

toggleBlankFilter(field: string, mode: BlankMode): void
NameTypeDescription
fieldstring
modeBlankMode

AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt