A filter builder and a multi-sort builder for a data table: rules of field, operator and value joined by and or or, saved as plain JSON, and a sort list ordered by priority.
- Saved views of a run table
- Audit log filters
- Eval result slices
- Spend reports
Examples
Installation
Installation is part of Pro
Pro components install from a licensed registry. The live preview stays open to everyone.
Props
- FilterBuilder fields
{ id, label, type, get, options? }[]- What a rule can filter on. type is text, number, select or date and decides the operators; get reads the cell value from a row; options are the choices of a select.
- value / defaultValue / onValueChange
QueryGroup- Default
{ join: "and", rules: [] } - The query: { join, rules: { id, field, op, value }[] }. Plain JSON, so it can be saved or put in a URL. Values are strings (numbers as "12.5", days as "2026-11-12"), a list for is any of, a pair for is between.
- compileQuery(group, fields)
(row) => boolean|undefined- Turns the query into one row test for DataTable's rowFilter. A rule with no value yet is skipped, and no live rules returns undefined (every row passes).
- addLabel / empty / aria-label
ReactNode / string- Default
"Add filter" - The add button, the text with no rules, and the name of the group.
- SortBuilder columns
{ id, label }[]- The columns that can be sorted; use the ids of your DataTable columns.
- SortBuilder value / defaultValue / onValueChange
{ id, desc }[]- Default
[] - The same shape as DataTable's sort. Order is priority: move a rule up or down, remove it, or change its column and direction.
- Operators
-- Text: contains, does not contain, is, is not, is empty. Number: = ≠ > ≥ < ≤, between, is empty. Select: is, is not, is any of, is empty. Date: on, before, after, between, is empty.
- Motion
-- Rules and sorts slide in and out over 180ms (ease out); reduced motion shows them at once.
- a11y
group- Each control is a native select, input or button with a name that says which rule it belongs to; changing the filter count is announced politely.
| Prop | Type | Default | Description |
|---|---|---|---|
| FilterBuilder fields | { id, label, type, get, options? }[] | - | What a rule can filter on. type is text, number, select or date and decides the operators; get reads the cell value from a row; options are the choices of a select. |
| value / defaultValue / onValueChange | QueryGroup | { join: "and", rules: [] } | The query: { join, rules: { id, field, op, value }[] }. Plain JSON, so it can be saved or put in a URL. Values are strings (numbers as "12.5", days as "2026-11-12"), a list for is any of, a pair for is between. |
| compileQuery(group, fields) | (row) => boolean | undefined | - | Turns the query into one row test for DataTable's rowFilter. A rule with no value yet is skipped, and no live rules returns undefined (every row passes). |
| addLabel / empty / aria-label | ReactNode / string | "Add filter" | The add button, the text with no rules, and the name of the group. |
| SortBuilder columns | { id, label }[] | - | The columns that can be sorted; use the ids of your DataTable columns. |
| SortBuilder value / defaultValue / onValueChange | { id, desc }[] | [] | The same shape as DataTable's sort. Order is priority: move a rule up or down, remove it, or change its column and direction. |
| Operators | - | - | Text: contains, does not contain, is, is not, is empty. Number: = ≠ > ≥ < ≤, between, is empty. Select: is, is not, is any of, is empty. Date: on, before, after, between, is empty. |
| Motion | - | - | Rules and sorts slide in and out over 180ms (ease out); reduced motion shows them at once. |
| a11y | group | - | Each control is a native select, input or button with a name that says which rule it belongs to; changing the filter count is announced politely. |
What it handles
- 01Offers the operators that fit a field's type: text contains and is, numbers compare and fall between, selects are one or any of a list, dates are on, before, after or between.
- 02Resets a rule when its field changes, and keeps what was typed when only its operator changes and the new operator can use it.
- 03Joins every rule with and or or from one select on the second rule, so a query is one group and reads in a single sentence.
- 04Skips a rule that has no value yet, so a half-built query never empties the table, and turns the rest into one row test with `compileQuery`.
- 05Keeps the whole query as plain JSON with string values, so it can be saved as a view, put in a URL or stored in a database column.
- 06Orders the sort rules by priority with a column, a direction and move up, move down and remove buttons, in the same shape as DataTable's `sort`.
States
- Rule added
- The row slides in and fades in
- 180ms, ease out
- Rule removed
- The row fades out and its space closes
- 180ms, ease out
- Value typed
- The table filters as you type, and the count of live filters updates
- none
- Hover or focus
- Icon buttons change colour
- 120ms, ease out
- Reduced motion
- Rows appear and go at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| Rule added | The row slides in and fades in | 180ms, ease out |
| Rule removed | The row fades out and its space closes | 180ms, ease out |
| Value typed | The table filters as you type, and the count of live filters updates | none |
| Hover or focus | Icon buttons change colour | 120ms, ease out |
| Reduced motion | Rows appear and go at once | 0ms |
Works with
When to use
When to use
- Letting people build their own view of a table: several rules over text, numbers, choices and dates, joined by and or or.
- A saved-views feature, where the query has to be stored as JSON and loaded back.
When not to use
- Two or three fixed filters people always use: chips are quicker: use Data Table.
- A quick search across every column: use Data Table.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Table Query Builder to my app and wire it to my own data.
- I need letting people build their own view of a table: several rules over text, numbers, choices and dates, joined by and or or. Set that up with the Knowns UI Table Query Builder.
- Which Table Query Builder props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "table-query-builder" }) and search_docs({ query: "table query builder" }). Pro props, full examples and source come back once your license key is in the MCP config.