"use client"; import { ColumnDef, flexRender, getCoreRowModel, getSortedRowModel, getPaginationRowModel, SortingState, useReactTable, } from "@tanstack/react-table"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Button } from "@/components/ui/button"; import { useState } from "react"; import { ChevronLeft, ChevronRight, ChevronsUpDown, ChevronUp, ChevronDown } from "lucide-react"; interface DataTableProps { columns: ColumnDef[]; data: TData[]; onRowClick?: (row: TData) => void; } export function DataTable({ columns, data, onRowClick, }: DataTableProps) { const [sorting, setSorting] = useState([]); const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getPaginationRowModel: getPaginationRowModel(), onSortingChange: setSorting, state: { sorting }, initialState: { pagination: { pageSize: 15 } }, }); return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => (
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())} {header.column.getCanSort() && ( {header.column.getIsSorted() === "asc" ? ( ) : header.column.getIsSorted() === "desc" ? ( ) : ( )} )}
))}
))}
{table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( onRowClick?.(row.original)} > {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No results. )}

{table.getFilteredRowModel().rows.length} row(s)

); }