Data Table Filter
<zn-data-table-filter>
ZnDataTableFilter
The filter for data tables: a funnel that opens a field / operator / value builder, and chips for the rules that apply.
<zn-data-table-filter filters="[{"id":"title","name":"Title","operators":["eq"]},{"id":"author","name":"Author","operators":["eq","fuzzy"]},{"id":"genre","name":"Genre","options":{"action":"Action","comedy":"Comedy","drama":"Drama","fantasy":"Fantasy","horror":"Horror","mystery":"Mystery","romance":"Romance","thriller":"Thriller","sci-fi":"ScienceFiction"},"maxOptionsVisible":"3","operators":["eq","in"]},{"id":"rating","name":"Rating","type":"number","operators":["eq","gt","gte","lt","lte"]},{"id":"created","name":"Created","type":"date","operators":["eq","before","after"]}]"> </zn-data-table-filter>
The funnel opens a popover headed Filters · Show records that match all of these. Each row is a rule: pick a field, an operator and a value, or remove the row with its trash button. + Add filter adds a row for a field not yet used, and Clear all removes every rule. Nothing reaches the table until Apply, which closes the popover and applies every rule that has a field, an operator and a value; while any row is still empty the heading says so. Closing the popover with Escape or a click outside it discards the edits.
The rules that apply show as chips after the funnel, and the funnel’s badge counts them. A chip’s text opens
the popover again, and its X removes that rule. Inside a
zn-data-table or
zn-report-table the funnel sits in the header and the
chips get a row of their own under it.
A rule starts on its field’s first declared operator, and the operator list offers the rest. Picking another field resets the operator and the value. The value control follows the field:
-
A field with
options, or aboolfield, gets a select. Withinorninit becomes a multi-select. -
A
numberfield gets a number input, and adateordateTimefield a date input. -
Any other field gets a text input. With
inornin, separate values with commas.
With more than eight fields, the field select is searchable: open it and type, and the placeholder reads
Search N fields....
default-filters takes a comma-separated list of field ids. When the popover opens with nothing
applied, it starts with an empty row for each of them, rather than one blank row.
<zn-data-table-filter default-filters="status" filters='[ {"id":"status","name":"Status","options":{"open":"Open","closed":"Closed"},"operators":["eq","neq"]}, {"id":"tag","name":"Tag","options":{"bug":"Bug","chore":"Chore","feature":"Feature"},"operators":["in","nin"]}, {"id":"owner","name":"Owner","operators":["contains","eq"]} ]'> </zn-data-table-filter>
The component emits zn-filter-change and exposes the query on value, encoded as
zn-query-builder encodes it: base64 of [{key, comparator, value}], or
'' when no rule applies. It only emits when that value changes. A multi-select’s values are
joined with spaces, and activeCount reports how many rules apply.
Setting value from outside rebuilds the rules, so a filter restored from a shared URL through
zn-data-table’s
sharable sync shows its chips straight
away.
Typeahead
Inside a zn-data-table, a text field suggests values from the rows the table has already
loaded, matched case-insensitively against what has been typed, keyed on the column whose name matches the
field’s id. Set suggestions yourself, as {[fieldId]: string[]}, to offer something
else.
Showing the Chips Elsewhere
Set another filter as a filter’s source property and it shows only that filter’s chips, while
that filter stops showing its own. The tables use this to keep the funnel in their header and the chips in a
row under it.
<div> <zn-data-table-filter id="chips-source" filters='[{"id":"status","name":"Status","options":{"open":"Open","closed":"Closed"},"operators":["eq"]}]'> </zn-data-table-filter> <zn-data-table-filter id="chips-row"></zn-data-table-filter> </div> <script> document.getElementById('chips-row').source = document.getElementById('chips-source'); </script>
Examples
Basic Text Filters
Create simple text-based filters with equality and fuzzy search operators.
<zn-data-table-filter filters="[{"id":"name","name":"Name","operators":["eq","fuzzy"]},{"id":"email","name":"Email","operators":["eq","fuzzy"]},{"id":"company","name":"Company","operators":["eq"]}]" name="text-filters"> </zn-data-table-filter>
Number Filters with Operators
Use number fields with comparison operators: they read is more than, is at least,
is less than and is at most.
<zn-data-table-filter filters="[{"id":"age","name":"Age","type":"number","operators":["eq","gt","gte","lt","lte"]},{"id":"price","name":"Price","type":"number","operators":["eq","gt","lt"]},{"id":"quantity","name":"Quantity","type":"number","operators":["eq","gte","lte"]}]" name="number-filters"> </zn-data-table-filter>
Date Filters
Filter by dates with before, after and equal operators. A date field takes a date, and a
dateTime field a date and a time.
Values are encoded the way zn-query-builder encodes them, and changing the operator re-encodes
the date. dateSubmitFormat picks the wire format: legacy (the default — seconds
for eq/neq, otherwise minutes from now, negated for before),
timestamp (milliseconds) or iso.
<zn-data-table-filter filters="[{"id":"created","name":"Created Date","type":"date","operators":["eq","before","after"]},{"id":"modified","name":"Modified Date","type":"date","operators":["before","after"]},{"id":"due_date","name":"Due Date","type":"dateTime","dateSubmitFormat":"iso","operators":["eq","before","after"]}]" name="date-filters"> </zn-data-table-filter>
Dropdown Options
Use predefined options for select-based filtering.
<zn-data-table-filter filters="[{"id":"status","name":"Status","options":{"open":"Open","in_progress":"In Progress","closed":"Closed"},"operators":["eq","in"]},{"id":"priority","name":"Priority","options":{"low":"Low","medium":"Medium","high":"High","critical":"Critical"},"operators":["eq","in"]}]" name="option-filters"> </zn-data-table-filter>
Mixed Filter Types
Combine different field types in a single filter component.
<zn-data-table-filter filters="[{"id":"product","name":"Product Name","operators":["eq","fuzzy"]},{"id":"category","name":"Category","options":{"electronics":"Electronics","clothing":"Clothing","books":"Books"},"operators":["eq","in"]},{"id":"price","name":"Price","type":"number","operators":["eq","gt","lt"]},{"id":"in_stock","name":"In Stock","type":"boolean","operators":["eq"]}]" name="mixed-filters"> </zn-data-table-filter>
Employee Filter Example
A practical example for filtering employee data.
<zn-data-table-filter filters="[{"id":"employee_name","name":"Employee Name","operators":["eq","fuzzy"]},{"id":"department","name":"Department","options":{"engineering":"Engineering","sales":"Sales","marketing":"Marketing","hr":"Human Resources","finance":"Finance"},"operators":["eq","in"]},{"id":"hire_date","name":"Hire Date","type":"date","operators":["before","after"]},{"id":"salary","name":"Salary","type":"number","operators":["gt","lt"]}]" name="employee-filters"> </zn-data-table-filter>
E-commerce Filter Example
Filter products with various criteria.
<zn-data-table-filter filters="[{"id":"title","name":"Product Title","operators":["eq","fuzzy"]},{"id":"brand","name":"Brand","operators":["eq"]},{"id":"category","name":"Category","options":{"electronics":"Electronics","clothing":"Clothing","home":"Home & Garden","sports":"Sports","toys":"Toys"},"maxOptionsVisible":3,"operators":["eq","in"]},{"id":"price","name":"Price","type":"number","operators":["eq","gt","gte","lt","lte"]},{"id":"rating","name":"Rating","type":"number","operators":["gte"]},{"id":"release_date","name":"Release Date","type":"date","operators":["before","after"]}]" name="product-filters"> </zn-data-table-filter>
Content Library Filter
Filter media content like books, movies, or articles.
<zn-data-table-filter filters="[{"id":"title","name":"Title","operators":["eq","fuzzy"]},{"id":"author","name":"Author","operators":["eq","fuzzy"]},{"id":"genre","name":"Genre","options":{"action":"Action","comedy":"Comedy","drama":"Drama","fantasy":"Fantasy","horror":"Horror","mystery":"Mystery","romance":"Romance","thriller":"Thriller","sci-fi":"Science Fiction"},"maxOptionsVisible":3,"operators":["eq","in"]},{"id":"rating","name":"Rating","type":"number","operators":["eq","gt","gte","lt","lte"]},{"id":"published","name":"Published Date","type":"date","operators":["eq","before","after"]}]" name="content-filters"> </zn-data-table-filter>
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
defaultFilters
default-filters
|
Fields to offer an empty rule for when the builder opens with nothing applied. |
string
|
''
|
|
suggestions
|
Typeahead values per field. zn-data-table fills this from the rows it has loaded.
|
Record
|
{}
|
|
source
|
Another filter to show the chips of. This element then renders only that filter’s chips, and that filter stops rendering its own, so a table can keep the funnel in its header and the chips under it. |
ZnDataTableFilter | null
|
null
|
|
activeCount
|
Number of rules that apply. |
number
|
- | |
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Events
| Name | React Event | Description | Event Detail |
|---|---|---|---|
zn-filter-change |
|
Emitted when the applied rules change. Read the encoded query off value. |
- |
zn-clear |
|
Emitted when clear() removes every rule. |
- |
Methods
| Name | Description | Arguments |
|---|---|---|
show() |
Opens the filter builder. | - |
hide() |
Closes the filter builder. | - |
clear() |
Removes every rule. | - |
Dependencies
This component automatically imports the following dependencies.
<zn-button><zn-color-picker><zn-icon><zn-input><zn-opt-group><zn-option><zn-popup><zn-select><zn-slash-item><zn-slash-menu><zn-tag><zn-tooltip>