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';
OptionTypeDefaultDescription
debounceMsnumber300Debounce delay for filter input
caseSensitivebooleanfalseCase-sensitive string matching
trimInputbooleantrueTrim whitespace from filter input
useWorkerbooleantrueUse Web Worker for datasets >1000 rows
filterPanelRendererFilterPanelRenderer-Custom filter panel renderer
valuesHandlerFilterValuesHandler-Async handler to fetch unique filter values
filterHandlerFilterHandler<TRow>-Async handler to apply filters remotely
PropertyTypeDescription
filterablebooleanEnable filtering for this column
filterType'text' | 'select' | 'number' | 'date'Filter UI type
filterOptionsunknown[]Predefined options for select filters
MethodSignatureDescription
setFilter(field, value) => voidSet filter value for a column
getFilters() => FilterModel[]Get all current filters
clearFilters() => voidClear all filters
clearFilter(field) => voidClear filter for a specific column
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
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). Uses sourceRows to include all values regardless of current filter. When a column has filterValue, individual extracted values are returned.

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

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