⬆️ Migrate @tanstack/react-table to 9.x (#2509)

This commit is contained in:
Yurii Motov
2026-10-08 17:50:25 +02:00
committed by GitHub
parent f27b472150
commit 0007f609ec
5 changed files with 34 additions and 26 deletions
+26 -20
View File
@@ -1,9 +1,11 @@
import {
type ColumnDef,
createPaginatedRowModel,
flexRender,
getCoreRowModel,
getPaginationRowModel,
useReactTable,
type RowData,
rowPaginationFeature,
tableFeatures,
useTable,
} from "@tanstack/react-table"
import {
ChevronLeft,
@@ -29,20 +31,26 @@ import {
TableRow,
} from "@/components/ui/table"
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[]
const dataTableFeatures = tableFeatures({
rowPaginationFeature,
paginatedRowModel: createPaginatedRowModel(),
})
export type DataTableFeatures = typeof dataTableFeatures
interface DataTableProps<TData extends RowData> {
columns: ColumnDef<DataTableFeatures, TData>[]
data: TData[]
}
export function DataTable<TData, TValue>({
export function DataTable<TData extends RowData>({
columns,
data,
}: DataTableProps<TData, TValue>) {
const table = useReactTable({
}: DataTableProps<TData>) {
const table = useTable({
features: dataTableFeatures,
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
})
return (
@@ -70,7 +78,7 @@ export function DataTable<TData, TValue>({
{table.getRowModel().rows.length ? (
table.getRowModel().rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => (
{row.getAllCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
@@ -95,13 +103,13 @@ export function DataTable<TData, TValue>({
<div className="flex flex-col sm:flex-row sm:items-center gap-4">
<div className="text-sm text-muted-foreground">
Showing{" "}
{table.getState().pagination.pageIndex *
table.getState().pagination.pageSize +
{table.state.pagination.pageIndex *
table.state.pagination.pageSize +
1}{" "}
to{" "}
{Math.min(
(table.getState().pagination.pageIndex + 1) *
table.getState().pagination.pageSize,
(table.state.pagination.pageIndex + 1) *
table.state.pagination.pageSize,
data.length,
)}{" "}
of{" "}
@@ -111,15 +119,13 @@ export function DataTable<TData, TValue>({
<div className="flex items-center gap-x-2">
<p className="text-sm text-muted-foreground">Rows per page</p>
<Select
value={`${table.getState().pagination.pageSize}`}
value={`${table.state.pagination.pageSize}`}
onValueChange={(value) => {
table.setPageSize(Number(value))
}}
>
<SelectTrigger className="h-8 w-[70px]">
<SelectValue
placeholder={table.getState().pagination.pageSize}
/>
<SelectValue placeholder={table.state.pagination.pageSize} />
</SelectTrigger>
<SelectContent side="top">
{[5, 10, 25, 50].map((pageSize) => (
@@ -136,7 +142,7 @@ export function DataTable<TData, TValue>({
<div className="flex items-center gap-x-1 text-sm text-muted-foreground">
<span>Page</span>
<span className="font-medium text-foreground">
{table.getState().pagination.pageIndex + 1}
{table.state.pagination.pageIndex + 1}
</span>
<span>of</span>
<span className="font-medium text-foreground">