"use client" import * as React from "react" import { ColumnDef, flexRender, getCoreRowModel, useReactTable, } from "@tanstack/react-table" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { ChevronLeft, ChevronRight } from "lucide-react" interface DataTableProps { columns: ColumnDef[] data: TData[] searchKey?: string onSearch?: (value: string) => void pageCount?: number page?: number onPageChange?: (page: number) => void } export function DataTable({ columns, data, searchKey, onSearch, pageCount, page, onPageChange, }: DataTableProps) { // eslint-disable-next-line react-hooks/incompatible-library const table = useReactTable({ data: data || [], columns, getCoreRowModel: getCoreRowModel(), manualPagination: true, pageCount: pageCount, }) return (
{searchKey && onSearch && (
onSearch(event.target.value)} className="max-w-sm" />
)}
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} ) })} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( Sonuç bulunamadı. )}
{(pageCount !== undefined && page !== undefined && onPageChange) && (
Sayfa {page} / {pageCount || 1}
)}
) }