Created
June 26, 2023 06:55
-
-
Save Restoration/5419d0b782f3b9c6c631638d680f849e to your computer and use it in GitHub Desktop.
This file contains 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 from 'react'; | |
import { makeStyles } from '@material-ui/core/styles'; | |
import Table from '@material-ui/core/Table'; | |
import TableBody from '@material-ui/core/TableBody'; | |
import TableCell from '@material-ui/core/TableCell'; | |
import TableContainer from '@material-ui/core/TableContainer'; | |
import TableHead from '@material-ui/core/TableHead'; | |
import TableRow from '@material-ui/core/TableRow'; | |
import Paper from '@material-ui/core/Paper'; | |
const useStyles = makeStyles({ | |
stickyTableColumn: { | |
position: 'sticky', | |
left: 0, | |
backgroundColor: 'white', | |
zIndex: 1, | |
} | |
}); | |
export default function StickyTable() { | |
const classes = useStyles(); | |
const data = [ | |
["Row 1", "Cell 1", "Cell 2", "Cell 3"], | |
["Row 2", "Cell 4", "Cell 5", "Cell 6"], | |
["Row 3", "Cell 7", "Cell 8", "Cell 9"], | |
]; | |
return ( | |
<TableContainer component={Paper}> | |
<Table stickyHeader> | |
<TableHead> | |
<TableRow> | |
{data[0].map((header, index) => ( | |
<TableCell | |
key={index} | |
className={index === 0 ? classes.stickyTableColumn : ''} | |
> | |
{header} | |
</TableCell> | |
))} | |
</TableRow> | |
</TableHead> | |
<TableBody> | |
{data.slice(1).map((row, rowIndex) => ( | |
<TableRow key={rowIndex}> | |
{row.map((cell, cellIndex) => ( | |
<TableCell | |
key={cellIndex} | |
className={cellIndex === 0 ? classes.stickyTableColumn : ''} | |
> | |
{cell} | |
</TableCell> | |
))} | |
</TableRow> | |
))} | |
</TableBody> | |
</Table> | |
</TableContainer> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MUI: A component is changing the controlled value state of Select to be uncontrolled.
Elements should not switch from uncontrolled to controlled (or vice versa).
Decide between using a controlled or uncontrolled Select element for the lifetime of the component.
The nature of the state is determined during the first render. It's considered controlled if the value is not
undefined
.More info: