"use client" import * as React from "react" import { ColumnDef, flexRender, getCoreRowModel, useReactTable, SortingState, getSortedRowModel, HeaderGroup, Header, Row, Cell } from "@tanstack/react-table" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" interface DataTableProps { columns: ColumnDef[] data: TData[] } export function DataTable({ columns, data, }: DataTableProps) { const [sorting, setSorting] = React.useState([]) // eslint-disable-next-line react-hooks/incompatible-library const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), // Pagination is handled server-side in the main page, so we don't strictly need client-side pagination here // unless we mix both. For now, let's keep it simple and just render rows. // If we pass 20 items, it renders 20 items. // getPaginationRowModel: getPaginationRowModel(), onSortingChange: setSorting, getSortedRowModel: getSortedRowModel(), state: { sorting, }, manualPagination: true, // Tell table we handle pagination manually }) return (
{table.getHeaderGroups().map((headerGroup: HeaderGroup) => ( {headerGroup.headers.map((header: Header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} ) })} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row: Row) => ( {row.getVisibleCells().map((cell: Cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( Sonuç bulunamadı. )}
) }