material-table - 在反应js中从外部材料表单击按钮时在材料表中添加行
解决方案
进口import { forwardRef } from "react";
称呼
const addActionRef = React.useRef();
将此代码包含在您想要按钮的位置。我在这里使用材质 ui 按钮
<Button
color="primary"
variant="contained"
onClick={() => addActionRef.current.click()} //The line you need
>
Add new item
</Button>
并覆盖材料表中的动作
components = {
{
Action: props => {
//If isn't the add action
if (typeof props.action === typeof Function || props.action.tooltip !== 'Add') {
return <MTableAction { ...props
}
/>
} else {
return <div ref = {
addActionRef
}
onClick = {
props.action.onClick
}
/>;
}
}
}
}
如果你有任何问题,请询问。我在这里使用了带有材料 ui 的 react js。
https://github.com/mbrn/material-table/issues/2133
这个链接可能对你有帮助....这是我得到答案的地方
推荐阅读
- javascript - Apple MapKit JS 是否需要会员计划?
- javascript - 通过浏览器中的 Javascript 在 iOS 上保存 Zip 文件
- php - 如何避免在 Laravel 5.5 的每个请求中检查 MySQL 连接?
- firebase - 主题消息传递是否适用于 chrome 扩展?
- python - VS Code 中的一些设置
- php - Laravel:刀片中的未定义变量?
- excel - EXCEL VBA 不完全匹配自动过滤器
- c++ - 插槽调用了两次 qt
- java - 导入无法解决(Junit)
- javascript - 当用户单击一个选项时,用一个勾号或 html 中的任何内容标记它