Data Table
Filters
Faceted multi-select filters above the table, with static or async options from your API.
Preview
| Name | Role | Status |
|---|---|---|
| Ada Hopper | Admin | Active |
| Ada Lovelace | Admin | Active |
| Ada Turing | Admin | Active |
| Alan Johnson | Editor | Banned |
| Alan Ritchie | Editor | Banned |
| Alan Thompson | Editor | Banned |
| Barbara Hamilton | Admin | Active |
| Barbara Johnson | Admin | Active |
| Barbara Ritchie | Admin | Active |
| Dennis Hopper | Editor | Banned |
Wyświetlanie 1–10 z 36
Usage
Each filter is a multi-select dropdown next to the search input. It owns one
query parameter and stores picks comma-separated, like ?roleId=1,3. Changing a
filter returns to page one.
<ContentDataTable
id="users-table"
filters={[
{
id: 'status',
label: 'Status',
options: [
{ value: 'active', label: 'Active' },
{ value: 'banned', label: 'Banned' },
],
},
]}
columns={columns}
edges={data.edges}
pageInfo={data.pageInfo}
order={{ defaultOrder: { column: 'name', order: 'asc' } }}
/>Static options are searched on the client.
Panel layout
With several filters, set filtersLayout="panel". The toolbar keeps the search
and one Filters button that shows how many filters are on. It opens a panel
under the toolbar with a select per filter. Pick values, then press
Show results to apply them together and go back to page one. Clear all
empties the selects.
| Name | Role | Status |
|---|---|---|
| Ada Hopper | Admin | Active |
| Ada Lovelace | Admin | Active |
| Ada Turing | Admin | Active |
| Alan Johnson | Editor | Banned |
| Alan Ritchie | Editor | Banned |
| Alan Thompson | Editor | Banned |
| Barbara Hamilton | Admin | Active |
| Barbara Johnson | Admin | Active |
| Barbara Ritchie | Admin | Active |
| Dennis Hopper | Editor | Banned |
Wyświetlanie 1–10 z 36
<ContentDataTable
id="users-table"
filters={filters}
filtersLayout="panel"
columns={columns}
edges={data.edges}
pageInfo={data.pageInfo}
order={{ defaultOrder: { column: 'name', order: 'asc' } }}
/>The URL works the same as the dropdowns: one query parameter per filter. A
filter with single gets an "all" option at the top of its select. An
onSearch filter lists what onSearch('') returns, so return the most useful
options first.
A custom table can use the same panel. Render FiltersPanelToggle in your
toolbar and FiltersPanelDataTable under it, both from
@vitnode/core/components/table/filters-panel, inside your
DataTableNavigationProvider.
Async options
For long lists, pass onSearch instead. It runs when the dropdown opens and
400ms after typing stops. Return results already filtered and capped by the
server.
import type { FilterOption } from '@vitnode/core/components/table/filters'
import { RoleFormat } from '@vitnode/core/components/role-format'
import { fetcher } from '@vitnode/core/tanstack/fetcher'
export const searchRoles = async (search: string): Promise<FilterOption[]> => {
const res = await fetcher({
plugin: '@vitnode/core',
method: 'get',
module: 'admin/roles',
path: '/list',
args: { query: { search, first: '20' } },
withPagination: true,
})
if (res.status !== 200) return []
const data = await res.json()
return data.edges.map((role) => ({
value: String(role.id),
label: <RoleFormat role={role} />,
keywords: role.name.map((item) => item.name),
}))
}filters={[{ id: 'roleId', label: 'Group', onSearch: searchRoles }]}Read it in the API
A filter only writes to the URL. The API route reads the parameter and adds the
where clause:
const roleIds = (query.roleId?.split(',') ?? [])
.filter(Boolean)
.map(Number)
.filter(id => !Number.isNaN(id))
where: roleIds.length ? inArray(core_users.roleId, roleIds) : undefined,API
Prop
Type