Skip to content

Instantly share code, notes, and snippets.

@craftdelivery
Created October 16, 2019 20:57
Show Gist options
  • Save craftdelivery/439c232507b827f3b33eb9dc86491b63 to your computer and use it in GitHub Desktop.
Save craftdelivery/439c232507b827f3b33eb9dc86491b63 to your computer and use it in GitHub Desktop.
Material UI Table With Sticky Header
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>
)
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