createFilterUrlCodec
function createFilterUrlCodec(input): object;Defined in: filters/url.ts:701
Bind a field → kind allow-list once and get encode/decode pairs — sugar for
composing with a URL-state codec (e.g. parseAsCodec(risonCodec(...))).
keepEmptyGroups (default false) is forwarded to decodeNode — set it
true for an interactive filter-builder whose tree lives in the URL, so a
freshly-added empty and/or group survives the round-trip (see
expandFilterNode). It does not affect decodeFilters (a flat list has
no groups).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ keepEmptyGroups?: boolean; kinds: FieldKindSpec; } |
input.keepEmptyGroups? |
boolean |
input.kinds |
FieldKindSpec |
Returns
Section titled “Returns”object
| Name | Type | Defined in |
|---|---|---|
decodeFilters() |
(compact) => FiltersRequest |
filters/url.ts:705 |
decodeNode() |
(compact) => FilterNode | null |
filters/url.ts:703 |
encodeFilters() |
(filters) => CompactLeaf[] |
filters/url.ts:704 |
encodeNode() |
(node) => CompactNode |
filters/url.ts:702 |
Example
Section titled “Example”import { createFilterUrlCodec } from "@xtandard/lib/filters";
const codec = createFilterUrlCodec({ kinds: { title: "text", status: "enum" } });
const compact = codec.encodeFilters([ { field: "title", filter: { kind: "text", operator: "startsWith", value: "Q3" } },]); // → [{ f: "title", o: "sw", v: "Q3" }]codec.decodeFilters(compact);// → [{ field: "title", filter: { kind: "text", operator: "startsWith", value: "Q3" } }]
codec.decodeNode({ not: { f: "status", o: "eq", v: "done" } });// → { type: "not", node: { type: "column", field: "status", filter: { kind: "enum", operator: "eq", value: "done" } } }