{sections.map((section, index) => (
<TableBody key={index}>
{section.map((row, rowIndex) => (
<TableRow
key={rowIndex}
sx={{
'&:nth-of-type(odd)': {
backgroundColor: 'zebra.odd',
},
'color': 'primary.main',
}}
>
{headers.map((header, i) => (
<TableCell
key={i}
component='th'
scope='col'
align='left'
sx={tableCellStyles}
>
<Typography
sx={{
color: 'primary.main',
fontWeight: 400,
fontSize: 14,
}}
>
{index === 0 && (row[header.toLowerCase()] ?? '')}
</Typography>
</TableCell>
))}
{headers.map((header, i) => (
<TableCell
key={i}
component='th'
scope='row'
align='left'
sx={tableCellStyles}
>
<Typography
sx={{
color: 'primary.main',
fontWeight: 400,
fontSize: 14,
}}
>
{index === 1 && (row[header.toLowerCase()] ?? '')}
</Typography>
</TableCell>
))}
{headers.map((header, i) => (
<TableCell
key={i}
component='th'
scope='col'
align='left'
sx={tableCellStyles}
>
<Typography
sx={{
color: 'primary.main',
fontWeight: 400,
fontSize: 14,
}}
>
{index === 2 && (row[header.toLowerCase()] ?? '')}
</Typography>
</TableCell>
))}
</TableRow>
))}
</TableBody>
))}
恢复:
您应该连续使用两个表,而不是使用一个表。代码应该像这样:
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Table>
<TableBody>
...
</TableBody>
</Table>
<Table>
<TableBody>
...
</TableBody>
</Table>
</Box>
<TableBody>
{[...Array(20).keys()].map(rowIndex => (
<TableRow
key={rowIndex}
sx={{
'&:nth-of-type(odd)': { backgroundColor: 'zebra.odd' },
color: 'primary.main',
}}
>
{[...Array(3).keys()].map(sectionIndex => (
headers.map((header, i) => (
<TableCell
key={i}
component="th"
scope={sectionIndex === 1 ? 'row' : 'col'}
align="left"
sx={tableCellStyles}
>
<Typography
sx={{
color: 'primary.main',
fontWeight: 400,
fontSize: 14,
}}
>
{sections[sectionIndex][rowIndex][header.toLowerCase()] ?? ''}
</Typography>
</TableCell>
))
))}
</TableRow>
))}
</TableBody>
在上面的代码中,您将收到您想要的3个部分的表格。我没有更改您的
component
和
scope
属性,但我认为您使用了错误。