Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

material ui table horizontal scroll

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>
    )
};
like image 677
Jerome Avatar asked Dec 28 '18 18:12

Jerome


People also ask

How do I make a horizontal scroll?

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.

How do you make a material table scrollable in react?

you can use maxBodyHeight property, which will create vertical scrollbar if data exceeding the given height. Save this answer.

How do you make a grid scrollable in MUI?

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.


1 Answers

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'.

Edit rm0yx1knxq

like image 183
Ryan Cogswell Avatar answered Nov 16 '22 00:11

Ryan Cogswell