【发布时间】:2021-10-28 02:31:04
【问题描述】:
我有一个表格,它呈现两个按钮,删除和编辑行。
在他们两个上,我都需要访问行 ID。
我尝试使用 customBodyRender 但它不起作用,我只有 dataIndex 和 rowIndex,但我需要的是实际的行对象值。
用代码更新问题
const columns = [
{
name: "id",
label: "Id",
options: {
display: false
}
},
{
name: "name",
label: "Name",
},
{
name: "Actions",
options: {
filter: false,
sort: false,
empty: true,
customBodyRender: (dataIndex, rowIndex) => {
return (
<>
<IconButton aria-label="edit" onClick={() => {
alert(dataIndex + " - " + rowIndex)
}}>
<EditIcon />
</IconButton>
<IconButton color="primary" aria-label="delete" style={{ marginLeft: "10px" }} onClick={() => {
alert(dataIndex)
}}>
<DeleteIcon />
</IconButton>
</>
);
}
}
}];
这就是 MUIDataTable 的使用方式
<MUIDataTable
title={"Lista de Turnos"}
data={shifts}
columns={columns}
options={{
selectableRowsHideCheckboxes: true,
textLabels: {
body: {
noMatch: 'Não foram encontrados registros para serem mostrados',
},
},
}}
/>
【问题讨论】:
-
您可以在问题中添加您的代码吗?
-
是的,当然,添加
标签: javascript reactjs material-ui mui-datatable