import { useTable, useFilters, useSortBy, Column, TableState, usePagination, } from 'react-table'; import { Table } from './Table'; import { multiple } from './filter-types'; import { NestedTable } from './NestedTable'; import { DatatableContent } from './DatatableContent'; import { defaultGetRowId } from './defaultGetRowId'; interface Props> { dataset: D[]; columns: readonly Column[]; getRowId?(row: D): string; emptyContentLabel?: string; initialTableState?: Partial>; isLoading?: boolean; defaultSortBy?: string; } export function NestedDatatable>({ columns, dataset, getRowId = defaultGetRowId, emptyContentLabel, initialTableState = {}, isLoading, defaultSortBy, }: Props) { const tableInstance = useTable( { defaultCanFilter: false, columns, data: dataset, filterTypes: { multiple }, initialState: { sortBy: defaultSortBy ? [{ id: defaultSortBy, desc: true }] : [], ...initialTableState, }, autoResetSelectedRows: false, getRowId, }, useFilters, useSortBy, usePagination ); return ( tableInstance={tableInstance} isLoading={isLoading} emptyContentLabel={emptyContentLabel} renderRow={(row, { key, className, role, style }) => ( cells={row.cells} key={key} className={className} role={role} style={style} /> )} /> ); }