Created
October 16, 2019 20:57
-
-
Save craftdelivery/439c232507b827f3b33eb9dc86491b63 to your computer and use it in GitHub Desktop.
Material UI Table With Sticky Header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { memo } from 'react' | |
import { | |
Checkbox, | |
Button, | |
FormControlLabel, | |
TableBody, | |
TableCell, | |
TableFooter, | |
TableHead, | |
TableRow, | |
} from '@material-ui/core' | |
import TableSticky from '../tablesticky' | |
// maxHeight defaults to window.innerHeight | |
// add prop maxHeight to TableSticky to specify height | |
export default memo(props => | |
<TableSticky yBottomOffset={15}> | |
<TableHead> | |
<TableRow> | |
<TableCell> | |
col1 | |
</TableCell> | |
<TableCell> | |
col2 | |
</TableCell> | |
</TableRow> | |
</TableHead> | |
<TableBody> | |
</TableBody> | |
<TableRow> | |
<TableCell> | |
data-col1 | |
</TableCell> | |
<TableCell> | |
data-col2 | |
</TableCell> | |
</TableRow> | |
</TableSticky> | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { memo } from 'react' | |
import { makeStyles } from '@material-ui/core/styles' | |
import { | |
Table, | |
} from '@material-ui/core' | |
export default memo(props => { | |
const { yBottomOffset=0, maxHeight=window.innerHeight } = props | |
const useStyles = makeStyles({ | |
tableWrapper: { | |
maxHeight: maxHeight - yBottomOffset, | |
overflow: 'auto', | |
}, | |
}) | |
const classes = useStyles() | |
return ( | |
<div className={classes.tableWrapper}> | |
<Table stickyHeader> | |
{props.children} | |
</Table> | |
</div> | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment