import * as React from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; interface DataTableProps { data: TData[]; columns: { accessorKey: keyof TData | ((row: TData) => any); header: string; cell?: (row: TData) => React.ReactNode; }[]; onRowClick?: (row: TData) => void; className?: string; } export function DataTable({ data, columns, onRowClick, className, }: DataTableProps) { return (
{columns.map((column, i) => ( {column.header} ))} {data.length === 0 ? ( No data available ) : ( data.map((row, i) => ( onRowClick?.(row)} className={onRowClick ? "cursor-pointer hover:bg-gray-50" : ""} > {columns.map((column, j) => ( {column.cell ? ( column.cell(row) ) : (
{typeof column.accessorKey === "function" ? column.accessorKey(row) : row[column.accessorKey] !== undefined ? String(row[column.accessorKey]) : ""}
)}
))}
)) )}
); }