reactjs - 创建通用表
问题描述
我正在创建一个通用动态表,其中在行尾有列、行和操作按钮。所有数据都按预期显示,但标题未显示在操作按钮上。
有没有办法在操作按钮上显示标题下划线?
数据:
[
{
"id": "1231",
"name": "Michael",
"phone": "11223311",
"medical": "YES"
},
{
"id": "32123",
"name": "Johnson",
"phone": "3311323",
"medical": "NO"
}
]
const headCells = [
{dataIndex: 'id', name: 'ID' },
{dataIndex: 'name', name: 'Name' },
{dataIndex: 'phone', name: 'Phone' },
{dataIndex: 'medical', name: 'Medical' }
];
const Header = ({ cols }) => {
return cols.map((col) => (
<TableCell>{col.name}</TableCell>
));
}
const Rows = ({ data, cols }) => {
if (data) {
return data.map((row) =>
<TableRow key={row.uuid}>
{cols.map(col => <TableCell>{row[col.dataIndex]}</TableCell>)}
<TableCell >
<IconButton>
<SearchIcon color="primary"/>
</IconButton>
</TableCell>
</TableRow>
);
}
else return [];
};
return(
<TableContainer component={Paper}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
<Header cols={headCells} />
</TableRow>
</TableHead>
<TableBody>
<Rows data={data} cols={headCells} />
</TableBody>
</Table>
</TableContainer>
)
解决方案
为什么不手动添加?:
const Header = ({ cols }) => {
return cols.map((col) => (
<TableCell >{col.name}</TableCell>
)).concat( <TableCell className='underline-header'>Actions</TableCell>);
}
CSS:
.underline-header {
text-decoration: underline;
}
推荐阅读
- excel - 文本框和组合框的重置命令
- html - 如何将水平的家谱变成垂直的?
- c# - 如何从 ItemsControl 中获取与 ItemsSource 以外的其他类的绑定?
- python-3.x - 在函数之间传递变量:调用返回的变量还是使用类?
- switch-statement - 将场景从关卡切换到主菜单时,不会加载脚本并且按钮不起作用。我该如何解决?
- python - 如何区分 SpanSelector 中的左右按钮?
- google-cast - 控制发送到 chromecast 的图像 URL 的播放持续时间
- typescript - 带有区分联合的打字稿条件类型
- javascript - 来自 Object.keys(data) 的 getElementById
- javascript - 尝试支持动画时 SVG 文本倒置