Loading...
Loading...
Compare original and translation side by side
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 |
https://data-table.openstatus.devnpx 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无限查询集成 |
https://data-table.openstatus.devscripts/detect-stack.shnpx shadcn@latest add https://data-table.openstatus.dev/r/data-table.jsonNext.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.shnpx shadcn@latest add https://data-table.openstatus.dev/r/data-table.json使用Next.js? 参考data-table-filters仓库——这是一个集成了所有块的完整Next.js应用。
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
"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
"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>
);
}npx shadcn@latest addnpx shadcn@latest addcommandSlotcommandSlot<DataTableInfinite
commandSlot={<DataTableFilterCommand schema={schema} tableId="my-table" />}
/><DataTableInfinite
commandSlot={<DataTableFilterCommand schema={schema} tableId="my-table" />}
/>sheetSlotsheetSlot<DataTableInfinite
sheetSlot={
<DataTableSheetDetails title="Details">{content}</DataTableSheetDetails>
}
/><DataTableInfinite
sheetSlot={
<DataTableSheetDetails title="详情">{content}</DataTableSheetDetails>
}
/>import { DataTableCellBadge } from "@/components/data-table/data-table-cell";
// Use in columnDef.cellimport { DataTableCellBadge } from "@/components/data-table/data-table-cell";
// 在columnDef.cell中使用FILTER_COMPONENTSFILTER_COMPONENTSimport { FILTER_COMPONENTS } from "@/components/data-table/data-table-filter-controls";
FILTER_COMPONENTS.myCustom = MyCustomFilterComponent;import { FILTER_COMPONENTS } from "@/components/data-table/data-table-filter-controls";
FILTER_COMPONENTS.myCustom = MyCustomFilterComponent;DataTableInfinitecommandSlotsheetSlottoolbarActionschartSlotfooterSlotDataTableInfinitecommandSlotsheetSlottoolbarActionschartSlotfooterSlotnpx shadcn@latest add .../r/data-table-schema.jsoncreateTableSchemacol.*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()npx shadcn@latest add .../r/data-table-schema.jsoncreateTableSchemacol.*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()npx shadcn@latest add .../r/data-table-drizzle.jsoncreateDrizzleHandler({ db, table, columnMapping, cursorColumn, schema }){ data, facets, totalRowCount, filterRowCount, nextCursor, prevCursor }npx shadcn@latest add .../r/data-table-drizzle.jsoncreateDrizzleHandler({ db, table, columnMapping, cursorColumn, schema }){ data, facets, totalRowCount, filterRowCount, nextCursor, prevCursor }npx shadcn@latest add .../r/data-table-query.jsoncreateDataTableQueryOptions({ queryKeyPrefix, apiEndpoint, searchParamsSerializer })npx shadcn@latest add .../r/data-table-query.jsoncreateDataTableQueryOptions({ queryKeyPrefix, apiEndpoint, searchParamsSerializer })--color-success/warning/error/info@/components.json<NuqsAdapter><Suspense>initialStatefield.string()field.string().default("")SheetField.type"readonly"generateSheetFields()FILTER_COMPONENTS--color-success/warning/error/infocomponents.json@/<NuqsAdapter><Suspense>initialStatefield.string()field.string().default("")SheetField.type"readonly"generateSheetFields()FILTER_COMPONENTS