'use client'; import { cn } from '@/utils/cn'; import { flexRender, getCoreRowModel, useReactTable, } from '@tanstack/react-table'; import type { ColumnDef } from '@tanstack/react-table'; import { Grid, GridBody, GridCell, GridHeader, GridRow } from './grid-table'; interface DataTableProps { columns: ColumnDef[]; data: TData[]; } export const ACTIONS = '__actions__'; export function TableButtons({ children, className, }: { children: React.ReactNode; className?: string; }) { return (
{children}
); } export function DataTable({ columns, data }: DataTableProps) { const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), }); return ( {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { if (header.column.id === ACTIONS) { return ( Actions ); } return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )} ); })} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => { if (cell.column.id === ACTIONS) { return ( {flexRender( cell.column.columnDef.cell, cell.getContext(), )} ); } return ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ); })} )) ) : (
No results.
)}
); }