⬆️ 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
+1 -1
View File
@@ -31,7 +31,7 @@
"@tanstack/react-query-devtools": "^5.104.0",
"@tanstack/react-router": "^1.170.39",
"@tanstack/react-router-devtools": "^1.167.2",
"@tanstack/react-table": "^8.21.3",
"@tanstack/react-table": "^9.2.4",
"axios": "1.20.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
+2 -1
View File
@@ -1,6 +1,7 @@
import type { ColumnDef } from "@tanstack/react-table"
import type { UserPublic } from "@/client"
import type { DataTableFeatures } from "@/components/Common/DataTable"
import { Badge } from "@/components/ui/badge"
import { cn } from "@/lib/utils"
import { UserActionsMenu } from "./UserActionsMenu"
@@ -9,7 +10,7 @@ export type UserTableData = UserPublic & {
isCurrentUser: boolean
}
export const columns: ColumnDef<UserTableData>[] = [
export const columns: ColumnDef<DataTableFeatures, UserTableData>[] = [
{
accessorKey: "full_name",
header: "Full Name",
+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">
+2 -1
View File
@@ -2,6 +2,7 @@ import type { ColumnDef } from "@tanstack/react-table"
import { Check, Copy } from "lucide-react"
import type { ItemPublic } from "@/client"
import type { DataTableFeatures } from "@/components/Common/DataTable"
import { Button } from "@/components/ui/button"
import { useCopyToClipboard } from "@/hooks/useCopyToClipboard"
import { cn } from "@/lib/utils"
@@ -31,7 +32,7 @@ function CopyId({ id }: { id: string }) {
)
}
export const columns: ColumnDef<ItemPublic>[] = [
export const columns: ColumnDef<DataTableFeatures, ItemPublic>[] = [
{
accessorKey: "id",
header: "ID",