Experimental — API may change before a stable release.
Converts FilterBridge filter state to a TanStackColumnFiltersState array.
function toTanStackColumnFilters<S extends FilterSchema>(
schema: S,
state: InferFilterState<S>,
options?: ToTanStackColumnFiltersOptions<S>
): TanStackColumnFiltersState- Iterates schema keys in declaration order.
- Skips
undefined, empty arrays[], and empty range objects{}. - Uses the filter key as the column
idby default. - Applies
options.columnIdsto remap filter keys to column IDs. - Does not mutate
state.
const columnFilters = toTanStackColumnFilters(invoiceFilters, {
search: 'acme',
status: 'paid',
amount: { min: 100, max: 2500 },
})
// [
// { id: 'search', value: 'acme' },
// { id: 'status', value: 'paid' },
// { id: 'amount', value: { min: 100, max: 2500 } },
// ]Maps filter keys to different column IDs when the TanStack column ID differs from the FilterBridge filter key.
toTanStackColumnFilters(schema, state, {
columnIds: {
search: 'customerName',
issuedAt: 'issuedDate',
},
})Converts a TanStackColumnFiltersState array back to FilterBridge state.
function fromTanStackColumnFilters<S extends FilterSchema>(
schema: S,
columnFilters: TanStackColumnFiltersState,
options?: FromTanStackColumnFiltersOptions<S>
): InferFilterState<S>- Maps column IDs back to filter keys using reverse of
options.columnIds. - Validates values against the schema. Invalid values are discarded.
- Removes empty strings, empty arrays, and empty range objects.
| Filter type | Accepted values |
|---|---|
text |
string (trimmed, non-empty) |
select |
string in options list |
multiSelect |
string[] (filtered) or comma-separated string |
boolean |
boolean, "true", "false", "1", "0" |
dateRange |
{ from?: string; to?: string } |
numberRange |
{ min?: number; max?: number } or [min, max] tuple |
Object of client-side filter functions compatible with TanStack Table's filterFns option.
const filterBridgeFilterFns: {
text: FilterFnLike
select: FilterFnLike
multiSelect: FilterFnLike
boolean: FilterFnLike
dateRange: FilterFnLike
numberRange: FilterFnLike
}const table = useReactTable({
data,
columns,
state: { columnFilters },
getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
filterFns: filterBridgeFilterFns,
})row.getValue(columnId)is cast to string.- Comparison is case-insensitive substring (
includes). - Returns
truewhenfilterValueis empty,undefined, ornull.
- Strict equality:
row.getValue(columnId) === filterValue. - Returns
truewhenfilterValueis empty,undefined, ornull.
filterValuemust be an array.- If the cell is an array: returns
trueif any cell value is infilterValue. - If the cell is a scalar: returns
trueif the scalar is infilterValue. - Returns
truewhenfilterValueis an empty array orundefined.
typeof filterValue !== 'boolean'→ returnstrue.- Strict equality:
row.getValue(columnId) === filterValue.
filterValuemust be{ from?: string; to?: string }.- Uses lexicographic ISO string comparison (
<,>). - Returns
truewhen range has nofromand noto. - Returns
falsewhen cell value is empty and a range bound is set.
filterValuemust be{ min?: number; max?: number }.- Cell value is parsed to
numberif not already. - Returns
falsewhen cell value isNaNand a bound is set. - Returns
truewhen neitherminnormaxis defined.
type TanStackColumnFilter = {
id: string
value: unknown
}type TanStackColumnFiltersState = TanStackColumnFilter[]type ToTanStackColumnFiltersOptions<S extends FilterSchema> = {
columnIds?: Partial<Record<keyof InferFilterState<S>, string>>
}type FromTanStackColumnFiltersOptions<S extends FilterSchema> = {
columnIds?: Partial<Record<keyof InferFilterState<S>, string>>
}type FilterFnLike = (
row: { getValue: (columnId: string) => unknown },
columnId: string,
filterValue: unknown
) => booleanStructurally compatible with TanStack Table's FilterFn without importing it.