Files
portabase/src/components/wrappers/table/data-table-with-pagination.tsx
T

39 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-11-11 14:56:33 +01:00
"use client"
import {useState} from "react";
import {
ColumnDef, getCoreRowModel, getPaginationRowModel, getSortedRowModel, SortingState, useReactTable
} from "@tanstack/react-table"
import {DataTable} from "@/components/wrappers/table/data-table";
import {TablePagination} from "@/components/wrappers/table/table-pagination";
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[]
data: TData[]
}
export function DataTableWithPagination<TData, TValue>({columns, data}: DataTableProps<TData, TValue>) {
const [sorting, setSorting] = useState<SortingState>([])
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onSortingChange: setSorting,
getSortedRowModel: getSortedRowModel(),
state: {
sorting,
},
})
return (
<div>
<DataTable table={table}/>
<TablePagination table={table}/>
</div>
)
}