Tal*_*orr 4 html css typescript reactjs material-ui
我已经按照以下说明构建了一个带有 React 和 Material UI 的简单表格: https: //material-ui.com/components/tables/#table。
是否有一个选项可以让滚动条从红色箭头开始?或者完全删除它?
先感谢您
代码
<TableContainer component={Paper} style={{maxHeight: 350}}>
<Table className={styles.table} size="small" stickyHeader>
<TableHead>
<TableRow >
<TableCell className={styles.header}>
<Checkbox checked={allSelected} onClick={handleSelectAll} color="primary"/>
</TableCell>
<TableCell className={styles.header} align="left">Name</TableCell>
{props.showAdmin && <TableCell className={styles.header}>Admin</TableCell>}
</TableRow>
</TableHead>
<TableBody>
{props.employees.map(empl => (
<TableRow key={empl.id}>
<TableCell>
<Checkbox checked={isSelected(empl.id)} onClick={() =>handleSelect(empl.id)} className={styles.checkBox} color="primary"/>
</TableCell>
<TableCell component="th" scope="row" style={{paddingRight: 30}}>{empl.name}</TableCell>
{props.showAdmin && <TableCell align="center"><Checkbox disabled checked={empl.isAdmin} className={styles.checkBox}/></TableCell>}
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
Run Code Online (Sandbox Code Playgroud)
风格
createStyles({
table: {
maxWidth: 350,
maxHeight: 300
},
header: {
backgroundColor: '#123456',
color: '#ffffff',
fontSize: 18
},
checkBox: {
paddingTop: 1,
paddingBottom: 1,
}
}),
);
Run Code Online (Sandbox Code Playgroud)
如果删除 的maxHeight样式TableContainer,滚动将会消失。
<TableContainer component={Paper} style={{ maxHeight: 350 }}>
Run Code Online (Sandbox Code Playgroud)
到
<TableContainer component={Paper}>
Run Code Online (Sandbox Code Playgroud)
如果你想从标题下方滚动,只需将相关的CSS添加到material-ui组件中Table即可TableBody。
<TableContainer component={Paper} style={{ maxHeight: 350 }}>
Run Code Online (Sandbox Code Playgroud)
参考:
网上试试:
| 归档时间: |
|
| 查看次数: |
21511 次 |
| 最近记录: |