Reputation: 2761
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>
)
};
Upvotes: 19
Views: 66877
Reputation: 1585
For me just wrapping my <Table>
with <TableContainer>
(without any attributes) worked fine
Upvotes: 1
Reputation: 80966
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'
.
Upvotes: 31