import { ColumnDef, flexRender, getCoreRowModel, useReactTable, createColumnHelper, getExpandedRowModel, ExpandedState, } from '@tanstack/react-table'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { Empty } from 'antd'; import React from 'react'; import { Button } from './ui/button'; import { LuChevronRight } from 'react-icons/lu'; import { cn } from '@/utils/style'; export type { ColumnDef }; export { createColumnHelper }; interface DataTableProps { columns: ColumnDef[]; data: TData[]; ExpandComponent?: React.ComponentType<{ row: TData }>; } export function DataTable({ columns, data, ExpandComponent, }: DataTableProps) { const [expanded, setExpanded] = React.useState({}); const canExpand = Boolean(ExpandComponent); const table = useReactTable({ data, columns, state: { expanded, }, onExpandedChange: setExpanded, getCoreRowModel: getCoreRowModel(), getRowCanExpand: () => canExpand, }); const columnLen = canExpand ? columns.length + 1 : columns.length; return (
{table.getHeaderGroups().map((headerGroup) => ( {canExpand && (
); }