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), createData('5', 356, 16.0, 49, 3.9), createData('6', 159, 6.0, 24, 4.0), createData('7', 237, 9.0, 37, 4.3), createData('8', 262, 16.0, 24, 6.0), createData('9', 305, 3.7, 67, 4.3), createData('10', 356, 16.0, 49, 3.9), ]; function sum(column: 'calories' | 'fat' | 'carbs' | 'protein') { return rows.reduce((acc, row) => acc + row[column], 0); } export default function TableStickyHeader() { return (
The table body is scrollable. {rows.map((row) => ( ))}
Row Calories Fat (g) Carbs (g) Protein (g)
{row.name} {row.calories} {row.fat} {row.carbs} {row.protein}
Totals {sum('calories').toFixed(2)} {sum('fat').toFixed(2)} {sum('carbs').toFixed(2)} {sum('protein').toFixed(2)}
{sum('calories') + sum('fat') + sum('carbs') + sum('protein')} Kcal
); }