import Box from '@mui/joy/Box'; import Button from '@mui/joy/Button'; import Table from '@mui/joy/Table'; import Typography from '@mui/joy/Typography'; import Sheet from '@mui/joy/Sheet'; function createData( name: string, calories: number, fat: number, carbs: number, protein: number, ) { return { name, calories, fat, carbs, protein }; } const rows = [ createData('1', 159, 6.0, 24, 4.0), createData('2', 237, 9.0, 37, 4.3), createData('3', 262, 16.0, 24, 6.0), createData('4', 305, 3.7, 67, 4.3), ]; export default function TableColumnPinning() { return ( ← Scroll direction → ({ '--TableCell-height': '40px', // the number is the amount of the header rows. '--TableHeader-height': 'calc(1 * var(--TableCell-height))', '--Table-firstColumnWidth': '80px', '--Table-lastColumnWidth': '144px', // background needs to have transparency to show the scrolling shadows '--TableRow-stripeBackground': 'rgba(0 0 0 / 0.04)', '--TableRow-hoverBackground': 'rgba(0 0 0 / 0.08)', overflow: 'auto', background: `linear-gradient(to right, ${theme.vars.palette.background.surface} 30%, rgba(255, 255, 255, 0)), linear-gradient(to right, rgba(255, 255, 255, 0), ${theme.vars.palette.background.surface} 70%) 0 100%, radial-gradient( farthest-side at 0 50%, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0) ), radial-gradient( farthest-side at 100% 50%, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0) ) 0 100%`, backgroundSize: '40px calc(100% - var(--TableCell-height)), 40px calc(100% - var(--TableCell-height)), 14px calc(100% - var(--TableCell-height)), 14px calc(100% - var(--TableCell-height))', backgroundRepeat: 'no-repeat', backgroundAttachment: 'local, local, scroll, scroll', backgroundPosition: 'var(--Table-firstColumnWidth) var(--TableCell-height), calc(100% - var(--Table-lastColumnWidth)) var(--TableCell-height), var(--Table-firstColumnWidth) var(--TableCell-height), calc(100% - var(--Table-lastColumnWidth)) var(--TableCell-height)', backgroundColor: 'background.surface', })} > *:first-child': { position: 'sticky', left: 0, boxShadow: '1px 0 var(--TableCell-borderColor)', bgcolor: 'background.surface', }, '& tr > *:last-child': { position: 'sticky', right: 0, bgcolor: 'var(--TableCell-headBackground)', }, }} > {rows.map((row) => ( ))}
Row Calories Fat (g) Carbs (g) Protein (g)
{row.name} {row.calories} {row.fat} {row.carbs} {row.protein}
); }