stickyHeader for DataTable #20275
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi James! I ran into the same issue when trying to use
Here’s a minimal example that works for me: <TableContainer style={{ maxHeight: '500px', overflowY: 'auto' }}>
<DataTable stickyHeader rows={rows} headers={headers}>
{({ rows, headers, getTableProps, getHeaderProps, getRowProps }) => (
<Table {...getTableProps()}>
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader key={header.key} {...getHeaderProps({ header })}>
{header.header}
</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow key={row.id} {...getRowProps({ row })}>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
)}
</DataTable>
</TableContainer> So in short: you’re not missing a prop, the key is making sure the Hope that helps! 😊 |
Beta Was this translation helpful? Give feedback.
-
For anyone wondering I managed to fix it by making the inner table have a maximum height as followed: <DataTable isSortable rows={filteredRows} headers={headers} stickyHeader>
{({
rows,
headers,
getTableProps,
getHeaderProps,
getRowProps,
}: {
rows: DataTableRow[];
headers: DataTableHeader[];
getHeaderProps: (options: any) => TableHeadProps;
getRowProps: (options: any) => TableRowProps;
getTableProps: () => TableBodyProps;
}) => (
<TableContainer>
<TableToolbarContent>
<TableToolbarSearch
placeholder={translations('searchPlaceholder')}
persistent
onChange={(e: any) => {
setSearchTerm(e.target.value);
}}
data-testid="search-input"
/>
<Dropdown
className={styles.terminalDropdownMenu}
label="Select a terminal"
items={terminalnames}
itemToString={(item: DropdownOption | null) => (item ? item.label : '')}
onChange={({ selectedItem }: { selectedItem: DropdownOption | null }) => {
setSelectedTerminal(selectedItem);
}}
selectedItem={selectedTerminal}
data-testid="terminal-input"
/>
</TableToolbarContent>
<Table stickyHeader {...getTableProps()} style={{maxHeight: '500px', overflowY: 'auto'}}>
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader key={header.header} {...getHeaderProps({ header })}>
{header.header}
</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => (
<TableRow
key={row.id}
{...getRowProps({ row })}
onClick={() => handleRowClick(runId, row.id)}
className={styles.clickableRow}
data-testid="table-row"
>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)}
</DataTable> |
Beta Was this translation helpful? Give feedback.
For anyone wondering I managed to fix it by making the inner table have a maximum height as followed: