I'm struggling with horizontal scrollbar for my material-ui. Although I read the documentation and went through some topics here, I can't find how to fix my issue. The horizontal scrollbar never shows up.. Quite annoying
Here is the subset of my code :
App.js
<div style={{ height: '100vh', overflow: 'auto', width: '600px' }}>
<TableHeader headerlabels={headers} datarows={resu} />
</div >
TableHeader.js
const HeaderTableCell = styled(TableCell)`
&&{
background-color:#092e68;
color:white;
top:0;
position:sticky;
}
`;
const CustomTableCell = styled(TableCell)`
&&{
background-color:white;
color:#092e68;
}
`;
// key, label
const TableHeader = props => {
const { headerlabels, datarows } = props
return (
<Table>
<TableHead >
<TableRow key={uuid.v4()} >
{headerlabels.map((label) =>
(<HeaderTableCell {...props} key={label}>{label}</HeaderTableCell>))}
</TableRow>
</TableHead>
<TableBody >
{datarows.map((value, id) =>
(
<TableRow key={id} >
{headerlabels.map((label) =>
(<CustomTableCell {...props} key={label}>{value[label]}</CustomTableCell>))}
</TableRow>
)
)}
</TableBody >
</Table>
)
};
Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.
you can use maxBodyHeight property, which will create vertical scrollbar if data exceeding the given height. Save this answer.
Scrolling to specific cellsscrollToIndexes() . The only argument that must be passed is an object containing the row index and the column index of the cell to scroll. If the row or column index is not present, the grid will not do any movement in the missing axis.
UPDATE At the time of my original answer, this was handled as indicated below (wrapping the Table in a Paper with overflowX: 'auto'
), but the current demo instead handles this by wrapping the Table
in a TableContainer
which handles the overflowX: 'auto'
.
If you look at the code for the Simple Table demo, you'll see that it handles this by wrapping the Table in a Paper with overflowX: 'auto'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With