data-table-filters
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseData Table Filters
数据表格筛选器
A shadcn registry for building filterable, sortable data tables with infinite scroll and virtualization. Start with the core block, then extend with optional blocks for command palette, cell renderers, sheet panels, store adapters, schema generation, Drizzle ORM helpers, and React Query integration.
这是一个shadcn注册表,用于构建具备筛选、排序、无限滚动和虚拟化功能的数据表格。从核心块开始,再通过可选块进行扩展,包括命令面板、单元格渲染器、侧边面板、存储适配器、Schema生成、Drizzle ORM工具以及React Query集成。
Registry Blocks
注册表块
Install any block via . The CLI handles dependencies, path rewriting, and CSS variable injection.
npx shadcn@latest add <url>| Block | Install URL | What it adds |
|---|---|---|
| data-table | | Core: table engine, store, 4 filter types, memory adapter (~52 files) |
| data-table-filter-command | | Command palette with history + keyboard shortcuts |
| data-table-cell | | 8 cell renderers (text, code, badge, boolean, number, status-code, level-indicator, timestamp) |
| data-table-sheet | | Row detail side panel (auto-installs cells) |
| data-table-nuqs | | nuqs URL state adapter |
| data-table-zustand | | zustand state adapter |
| data-table-schema | | Declarative schema system with |
| data-table-drizzle | | Drizzle ORM server-side helpers (auto-installs schema) |
| data-table-query | | React Query infinite query integration |
All URLs use base .
https://data-table.openstatus.dev通过命令安装任意块。CLI会处理依赖项、路径重写和CSS变量注入。
npx shadcn@latest add <url>| 块名称 | 安装URL | 新增内容 |
|---|---|---|
| data-table | | 核心功能:表格引擎、存储、4种筛选类型、内存适配器(约52个文件) |
| data-table-filter-command | | 带历史记录和键盘快捷键的命令面板 |
| data-table-cell | | 8种单元格渲染器(文本、代码、徽章、布尔值、数字、状态码、级别指示器、时间戳) |
| data-table-sheet | | 行详情侧边面板(自动安装单元格组件) |
| data-table-nuqs | | nuqs URL状态适配器 |
| data-table-zustand | | zustand状态适配器 |
| data-table-schema | | 带 |
| data-table-drizzle | | Drizzle ORM服务端工具(自动安装Schema) |
| data-table-query | | React Query无限查询集成 |
所有URL的基础地址为。
https://data-table.openstatus.devQuick Start
快速开始
- Run to detect the user's project setup
scripts/detect-stack.sh - Install core:
npx shadcn@latest add https://data-table.openstatus.dev/r/data-table.json - Scaffold a minimal working table (see below)
- Extend with additional blocks as needed
Next.js? Use the data-table-filters repo as a reference — it's a full Next.js app with all blocks wired up.
- 运行检测用户的项目配置
scripts/detect-stack.sh - 安装核心块:
npx shadcn@latest add https://data-table.openstatus.dev/r/data-table.json - 搭建一个最简可用表格(见下文)
- 根据需要添加额外块
使用Next.js? 参考data-table-filters仓库——这是一个集成了所有块的完整Next.js应用。
Minimal Working Table (Memory Adapter)
最简可用表格(内存适配器)
Note:internally rendersDataTableInfinite, which already wraps children withDataTableProviderandControlsProvider. You do NOT need to add these separately. The only wrapper you need isDataTableStoreSync(for the BYOS adapter).DataTableStoreProvider
tsx
"use client";
import { DataTableInfinite } from "@/components/data-table/data-table-infinite";
import type { DataTableFilterField } from "@/components/data-table/types";
import { useMemoryAdapter } from "@/lib/store/adapters/memory";
import { DataTableStoreProvider } from "@/lib/store/provider/DataTableStoreProvider";
import type { ColumnDef } from "@tanstack/react-table";
const columns: ColumnDef<YourData>[] = [
/* user's columns */
];
const filterFields: DataTableFilterField<YourData>[] = [
/* user's filters */
];
export function MyTable({ data }: { data: YourData[] }) {
const adapter = useMemoryAdapter(/* schema definition */);
return (
<DataTableStoreProvider adapter={adapter}>
<DataTableInfinite
columns={columns}
data={data}
filterFields={filterFields}
/>
</DataTableStoreProvider>
);
}注意:内部会渲染DataTableInfinite,该组件已用DataTableProvider和ControlsProvider包裹子组件。你无需单独添加这些组件。唯一需要的包裹组件是DataTableStoreSync(用于BYOS适配器)。DataTableStoreProvider
tsx
"use client";
import { DataTableInfinite } from "@/components/data-table/data-table-infinite";
import type { DataTableFilterField } from "@/components/data-table/types";
import { useMemoryAdapter } from "@/lib/store/adapters/memory";
import { DataTableStoreProvider } from "@/lib/store/provider/DataTableStoreProvider";
import type { ColumnDef } from "@tanstack/react-table";
const columns: ColumnDef<YourData>[] = [
/* 用户自定义列 */
];
const filterFields: DataTableFilterField<YourData>[] = [
/* 用户自定义筛选字段 */
];
export function MyTable({ data }: { data: YourData[] }) {
const adapter = useMemoryAdapter(/* schema定义 */);
return (
<DataTableStoreProvider adapter={adapter}>
<DataTableInfinite
columns={columns}
data={data}
filterFields={filterFields}
/>
</DataTableStoreProvider>
);
}Wiring Extension Blocks
扩展块集成
After installing a block via , wire it into the table.
npx shadcn@latest add通过命令安装块后,将其集成到表格中。
npx shadcn@latest addCommand Palette → commandSlot
commandSlot命令面板 → commandSlot
commandSlottsx
<DataTableInfinite
commandSlot={<DataTableFilterCommand schema={schema} tableId="my-table" />}
/>tsx
<DataTableInfinite
commandSlot={<DataTableFilterCommand schema={schema} tableId="my-table" />}
/>Sheet Detail Panel → sheetSlot
sheetSlot侧边详情面板 → sheetSlot
sheetSlottsx
<DataTableInfinite
sheetSlot={
<DataTableSheetDetails title="Details">{content}</DataTableSheetDetails>
}
/>tsx
<DataTableInfinite
sheetSlot={
<DataTableSheetDetails title="详情">{content}</DataTableSheetDetails>
}
/>Cell Renderers → column definitions
单元格渲染器 → 列定义
tsx
import { DataTableCellBadge } from "@/components/data-table/data-table-cell";
// Use in columnDef.celltsx
import { DataTableCellBadge } from "@/components/data-table/data-table-cell";
// 在columnDef.cell中使用Custom Filter Types → FILTER_COMPONENTS
FILTER_COMPONENTS自定义筛选类型 → FILTER_COMPONENTS
FILTER_COMPONENTSAll 4 filter types ship with core. To add custom types:
tsx
import { FILTER_COMPONENTS } from "@/components/data-table/data-table-filter-controls";
FILTER_COMPONENTS.myCustom = MyCustomFilterComponent;核心块已包含4种筛选类型。要添加自定义类型:
tsx
import { FILTER_COMPONENTS } from "@/components/data-table/data-table-filter-controls";
FILTER_COMPONENTS.myCustom = MyCustomFilterComponent;All Slot Props
所有插槽属性
DataTableInfinitecommandSlotsheetSlottoolbarActionschartSlotfooterSlotSee references/component-catalog.md for full wiring details.
DataTableInfinitecommandSlotsheetSlottoolbarActionschartSlotfooterSlot完整集成细节请参考references/component-catalog.md。
Store Adapter Configuration
存储适配器配置
- memory (default) — Ephemeral, zero config. For prototyping, embedded components, builders.
- nuqs — URL state. Shareable links, bookmarkable filters. Requires framework setup.
- zustand — Client state. For existing zustand apps, complex app state.
Install adapter block, swap in provider. See references/store-adapters.md.
- memory(默认)——临时存储,零配置。适用于原型开发、嵌入式组件、构建工具。
- nuqs——URL状态。支持可分享链接、可收藏的筛选条件。需要框架配置。
- zustand——客户端状态。适用于已使用zustand的应用、复杂应用状态管理。
安装适配器块,替换对应的Provider。详情请参考references/store-adapters.md。
Schema Generation
Schema生成
Install:
npx shadcn@latest add .../r/data-table-schema.jsonMap data model → + :
createTableSchemacol.*- →
stringcol.string().filterable("input") - →
numbercol.number().filterable("slider", { min, max }) - →
booleancol.boolean().filterable("checkbox") - →
Datecol.timestamp().filterable("timerange") - →
enumcol.enum(values).filterable("checkbox")
Presets: , , , , , , .
col.presets.logLevel().httpStatus().duration().timestamp().traceId().pathname().httpMethod()See references/schema-api.md.
安装命令:
npx shadcn@latest add .../r/data-table-schema.json将数据模型映射为 + :
createTableSchemacol.*- →
stringcol.string().filterable("input") - →
numbercol.number().filterable("slider", { min, max }) - →
booleancol.boolean().filterable("checkbox") - →
Datecol.timestamp().filterable("timerange") - →
enumcol.enum(values).filterable("checkbox")
预设项:、、、、、、。
col.presets.logLevel().httpStatus().duration().timestamp().traceId().pathname().httpMethod()详情请参考references/schema-api.md。
Server-Side Integration
服务端集成
Install:
npx shadcn@latest add .../r/data-table-drizzle.jsonScaffold route handler with .
createDrizzleHandler({ db, table, columnMapping, cursorColumn, schema })For non-Drizzle ORMs: implement response shape .
{ data, facets, totalRowCount, filterRowCount, nextCursor, prevCursor }See references/drizzle-integration.md.
安装命令:
npx shadcn@latest add .../r/data-table-drizzle.json使用搭建路由处理器。
createDrizzleHandler({ db, table, columnMapping, cursorColumn, schema })对于非Drizzle ORM:实现响应格式。
{ data, facets, totalRowCount, filterRowCount, nextCursor, prevCursor }详情请参考references/drizzle-integration.md。
Fetch Layer
获取层
Install:
npx shadcn@latest add .../r/data-table-query.jsonWire .
createDataTableQueryOptions({ queryKeyPrefix, apiEndpoint, searchParamsSerializer })See references/fetch-layer.md.
安装命令:
npx shadcn@latest add .../r/data-table-query.json集成。
createDataTableQueryOptions({ queryKeyPrefix, apiEndpoint, searchParamsSerializer })详情请参考references/fetch-layer.md。
Troubleshooting
故障排查
- Missing CSS vars: Core injects . Check cssVars applied to CSS.
--color-success/warning/error/info - Import path mismatches: shadcn CLI rewrites paths per
@/aliases.components.json - nuqs: silent failure or crash: Two required setup steps — in root layout AND
<NuqsAdapter>around the table component. See references/store-adapters.md.<Suspense> - nuqs: filters not applied from URL on load: Pass server-parsed search params as to the nuqs adapter. See the SSR Hydration section in references/store-adapters.md.
initialState - nuqs: phantom filters with empty string: Use (null default), not
field.string().field.string().default("") - Sheet dropdown missing: must match the filter type (not
SheetField.type) to get the filter dropdown. Use"readonly"to auto-derive from filter config.generateSheetFields() - Filter not rendering: Verify filter type string matches key.
FILTER_COMPONENTS - Tailwind v4: Registry targets v4. Class syntax differs from v3.
- 缺少CSS变量:核心块会注入。检查CSS中是否已应用这些cssVars。
--color-success/warning/error/info - 导入路径不匹配:shadcn CLI会根据中的别名重写
components.json路径。@/ - nuqs:无提示失败或崩溃:需要两个必要的配置步骤——在根布局中添加,并在表格组件周围包裹
<NuqsAdapter>。详情请参考references/store-adapters.md。<Suspense> - nuqs:加载时未从URL应用筛选条件:将服务端解析的搜索参数作为传递给nuqs适配器。详情请参考references/store-adapters.md中的SSR水合部分。
initialState - nuqs:空字符串导致的幽灵筛选器:使用(默认值为null),而非
field.string()。field.string().default("") - 侧边面板下拉菜单缺失:必须与筛选类型匹配(不能是
SheetField.type)才能显示筛选下拉菜单。使用"readonly"从筛选配置自动派生。generateSheetFields() - 筛选器未渲染:验证筛选类型字符串是否与的键匹配。
FILTER_COMPONENTS - Tailwind v4:注册表针对v4版本构建,类语法与v3不同。".replace(/"/g, '"'),