

















@virtuoso.dev/data-table is a virtualized React data table with row and column virtualization,
grouped data support, sticky columns, state persistence, and column resizing, reordering, and
visibility features.
It is the successor to TableVirtuoso when you need a table-specific API instead of a virtualized HTML table primitive. The recommended distribution is the shadcn-style wrapper published from virtuoso.dev, which gives you styled cells and headers while keeping the headless engine available for advanced behavior.
import { DataTable, DataTableCell, DataTableColumn, DataTableColumnHeader } from '@/components/ui/data-table'
import { localModel } from '@virtuoso.dev/data-table'
const products = [
{ id: 'SKU-001', name: 'Standing Desk', category: 'Office', price: 699, stock: 14 },
{ id: 'SKU-002', name: 'USB-C Dock', category: 'Peripherals', price: 229, stock: 42 },
{ id: 'SKU-003', name: 'Mechanical Keyboard', category: 'Peripherals', price: 169, stock: 28 },
{ id: 'SKU-004', name: 'Noise-canceling Headset', category: 'Audio', price: 319, stock: 9 },
]
const currency = new Intl.NumberFormat('en-US', {
currency: 'USD',
style: 'currency',
})
const model = localModel({ data: products })
export default function App() {
return (
<DataTable className="rounded-xl" model={model} style={{ height: 320 }}>
<DataTableColumn field="name">
<DataTableColumnHeader>Name</DataTableColumnHeader>
<DataTableCell className="font-medium">{({ cellValue }) => String(cellValue)}</DataTableCell>
</DataTableColumn>
<DataTableColumn field="category">
<DataTableColumnHeader>Category</DataTableColumnHeader>
<DataTableCell>{({ cellValue }) => String(cellValue)}</DataTableCell>
</DataTableColumn>
<DataTableColumn field="price">
<DataTableColumnHeader className="justify-end">Price</DataTableColumnHeader>
<DataTableCell className="text-right tabular-nums">{({ cellValue }) => currency.format(Number(cellValue))}</DataTableCell>
</DataTableColumn>
<DataTableColumn field="stock">
<DataTableColumnHeader className="justify-end">Stock</DataTableColumnHeader>
<DataTableCell className="text-right tabular-nums">{({ cellValue }) => String(cellValue)}</DataTableCell>
</DataTableColumn>
</DataTable>
)
}TableVirtuosoIf you are coming from TableVirtuoso, start by moving row rendering logic into DataTableColumn definitions:
itemContent becomes one or more DataTableCell rendererssticky, GroupHeaderCell, and ColumnGroupengineRef / engineId and scrollToRow$For teams already standardized on shadcn/ui, the wrapper keeps the migration surface small because the styled building blocks are installed into your app and can be edited like any other component.
See Migrating From TableVirtuoso for the full mapping.
Start with the two required setup tasks:
localModel() or remoteModel().DataTableColumn, headers, and cells.Then add the features your table needs:
Visual customization is covered separately:
MIT
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。