Skip to content

createTableBridge

function createTableBridge<C, G>(input): TableBridge<C, G>;

Defined in: filters/tanstack-table.ts:911

Bind a per-column mapping spec once and get converters between TanStack Table state and the filter model. The spec is plain data, so share it between the browser (table ⇄ URL) and the server (URL → FilterNode → adapter).

  • columns: column id → a *Column builder (how that column’s filter value maps to the model). A builder’s field renames the column to a model field.
  • globalFilter: the model fields a global search box matches (text).

Throws when two columns map to the same field, or a global-filter field is a column of another kind.

Type Parameter Default type
C extends TableColumns -
G extends readonly string[] []
Parameter Type
input { columns: C; globalFilter?: TableGlobalFilterOptions<G>; }
input.columns C
input.globalFilter? TableGlobalFilterOptions<G>

TableBridge<C, G>

import {
createTableBridge,
multiSelectColumn,
numberRangeColumn,
textColumn,
} from "@xtandard/lib/filters/tanstack-table";
const bridge = createTableBridge({
columns: {
name: textColumn(),
status: multiSelectColumn(),
price: numberRangeColumn({ field: "priceCents" }),
},
globalFilter: { fields: ["name", "sku"] },
});
bridge.kinds; // → { name: "text", status: "enum", priceCents: "number", sku: "text" }
const filters = bridge.toFilters([
{ id: "status", value: ["open"] },
{ id: "price", value: [1000, undefined] },
]);
// → [
// { field: "status", filter: { kind: "enum", operator: "inArray", values: ["open"] } },
// { field: "priceCents", filter: { kind: "number", operator: "gte", value: 1000 } },
// ]
bridge.fromFilters(filters);
// → [{ id: "status", value: ["open"] }, { id: "price", value: [1000, undefined] }]
bridge.toSort([{ id: "price", desc: true }]); // → [{ field: "priceCents", dir: "desc" }]
bridge.toFilterNode({ filters: [], globalFilter: "ada" });
// → { type: "or", nodes: [
// { type: "column", field: "name", filter: { kind: "text", operator: "contains", value: "ada" } },
// { type: "column", field: "sku", filter: { kind: "text", operator: "contains", value: "ada" } },
// ] }