'use client' import { ColumnDef, flexRender, getCoreRowModel, useReactTable, SortingState, getSortedRowModel } from '@tanstack/react-table' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../ui/table' import { useState } from 'react' interface DataTableProps { columns: ColumnDef[] data: TData[] className?: string } export function DataTable({ columns, data, className }: DataTableProps) { const [sorting, setSorting] = useState([]) const table = useReactTable({ data, columns, state: { sorting }, onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel() }) return (
{table.getHeaderGroups().map(headerGroup => ( {headerGroup.headers.map(header => ( {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())} ))} )) ) : ( No results )}
) }