import { type ColumnDef, flexRender, getCoreRowModel, type Row, useReactTable, } from "@tanstack/react-table" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" interface DataTableProps { columns: ColumnDef[] data: TData[] onRowContextMenu?: (row: Row, event: React.MouseEvent) => void } export function DataTable({ columns, data, onRowContextMenu, }: DataTableProps) { const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), enableRowSelection: true, }) return (
{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) => ( { onRowContextMenu?.(row, e) }} > {row.getVisibleCells().map((cell) => ( {flexRender( cell.column.columnDef.cell, cell.getContext(), )} ))} )) ) : ( No results. )}
) }