[英]Edit Button in React Datatable Component with ID
how to pass id in edit button of column cell in reactJS datatable component?如何在 reactJS 数据表组件的列单元格的编辑按钮中传递 id?
I have done it using "react-table" npm package.我已经使用“react-table”npm package 完成了它。 Without knowing your requirement exactly, it is bit hard to suggest use the package I have mentioned above.在不完全了解您的要求的情况下,建议使用我上面提到的 package 有点困难。
React Table - npm package反应表 - npm package
You can just have a look and see whether this is suitable for your requirement.你可以看看,看看这是否适合你的要求。
You need to use the cell property of the Columns.您需要使用列的单元格属性。
const columns = [
{
name: "Name",
selector: "name",
sortable: true,
},
{
name: "Phone",
selector: "phone",
sortable: true,
right: true,
},
{
key: "action",
text: "Action",
className: "action",
width: 100,
align: "left",
sortable: false,
cell: (record) => {
return (
<Fragment>
<button
className="btn btn-primary btn-sm"
onClick={() => {
onEdit(record);
}}
>
Edit
</button>
</Fragment>
);
},
},
];
In the onEdit method, you can manipulate the data or make the axios call and update the state to rerender.在 onEdit 方法中,您可以操作数据或进行 axios 调用并更新 state 以重新渲染。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.