reactjs - 从外部表组件访问选定的行数据
问题描述
我有一个用于表格的通用组件,该组件通过应用程序在不同页面中使用。现在,行的选择被保存在表格组件本身中。每当按下按钮时,我想从其父组件访问选定的数据行
解决方案
@jiltender
i fix my problem by doing this to get row data outside the table
rowProps={row =>(console.log(row)
)}
add this on parent components where u call the Table
<Table
sortByProps={[]}
columns={columns}
rowProps={row =>(setSelectedItems(row))} /// pass row props
/>
and the table side
add this in
function props
` `rowProps = () => ({}) })
function Table({ columns, data, showSpinnerProp, hiddenColumnsProps,getCellProps, getRowProps, height, sortByProps, source,
setSelectedItems,rowProps = () => ({}) }) {
this will return u all the select data you can call it before return
useEffect(() => {
setSelectedItems = selectedFlatRows;
rowProps(selectedFlatRows)
}, [selectedFlatRows]);
}
推荐阅读
- real-time-updates - jFugue可以同时使用两个播放器
- javascript - 如何在Javascript中将路径数组转换为对象?
- firebase - 如何在 Firebase 应用中生成安全邀请令牌?
- pdf - 如何制作将使用 IIS 直接下载 PDF 的 QR 码?
- c++ - 为什么逐个字符地读取字符比遍历整个文件字符串要快?
- docker - 您是否尝试将目录挂载到文件上(反之亦然)?检查指定的主机路径是否存在 - Docker from Windows WSL
- vb.net - 将数字转换为小时
- python - 仅使用 pandas 来获取给定开始时间、结束时间和可用时间块的 15 分钟时间块的所有可能组合?
- python - 如何使用 docker 运行 django 项目
- java - isInterrupted() 在 interrupt() 之后返回 false。中断是如何工作的?