简体   繁体   English

如何使表体垂直滚动material-ui?

[英]How to make table body vertically scrollable material-ui?

Property height doesn't apply to tbody element.属性高度不适用于tbody元素。 Is it possible to make table body scrollable?是否可以使表格主体可滚动?

const styles = {
  tableBody: {
    height: 300,
    overflow: "auto"
  }
};
 <Paper className={classes.root}>
    <Table>
      <TableHead>
        <TableRow>
          <TableCell>Dessert (100g serving)</TableCell>
          <TableCell align="right">Calories</TableCell>
          <TableCell align="right">Fat&nbsp;(g)</TableCell>
          <TableCell align="right">Carbs&nbsp;(g)</TableCell>
          <TableCell align="right">Protein&nbsp;(g)</TableCell>
        </TableRow>
      </TableHead>
      <TableBody className={classes.tableBody}>
        {rows.map(row => (
          <TableRow key={row.name}>
            <TableCell component="th" scope="row">
              {row.name}
            </TableCell>
            <TableCell align="right">{row.calories}</TableCell>
            <TableCell align="right">{row.fat}</TableCell>
            <TableCell align="right">{row.carbs}</TableCell>
            <TableCell align="right">{row.protein}</TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  </Paper>

Sandbox example https://codesandbox.io/embed/vigilant-night-zoidu沙盒示例https://codesandbox.io/embed/vigilant-night-zoidu

Wrap the table components to divs with some css like this:使用一些 css 将表格组件包装到 div 中,如下所示:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM