import { getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, TableOptions, TableState, useReactTable, } from '@tanstack/react-table'; import { defaultGetRowId } from './defaultGetRowId'; import { Table } from './Table'; import { NestedTable } from './NestedTable'; import { DatatableContent } from './DatatableContent'; import { BasicTableSettings } from './types'; interface Props> { dataset: D[]; columns: TableOptions['columns']; getRowId?(row: D): string; emptyContentLabel?: string; initialTableState?: Partial; isLoading?: boolean; initialSortBy?: BasicTableSettings['sortBy']; } export function NestedDatatable>({ columns, dataset, getRowId = defaultGetRowId, emptyContentLabel, initialTableState = {}, isLoading, initialSortBy, }: Props) { const tableInstance = useReactTable({ columns, data: dataset, initialState: { sorting: initialSortBy ? [initialSortBy] : [], ...initialTableState, }, defaultColumn: { enableColumnFilter: false, enableHiding: false, }, getRowId, autoResetExpanded: false, getCoreRowModel: getCoreRowModel(), getFilteredRowModel: getFilteredRowModel(), getSortedRowModel: getSortedRowModel(), getPaginationRowModel: getPaginationRowModel(), }); return ( tableInstance={tableInstance} isLoading={isLoading} emptyContentLabel={emptyContentLabel} renderRow={(row) => cells={row.getVisibleCells()} />} /> ); }