首页 > 解决方案 > 从外部表组件访问选定的行数据

问题描述

我有一个用于表格的通用组件,该组件通过应用程序在不同页面中使用。现在,行的选择被保存在表格组件本身中。每当按下按钮时,我想从其父组件访问选定的数据行

这是一个示例 https://codesandbox.io/s/naughty-pond-3e5jp

标签: reactjsreact-table

解决方案


@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]);
        
        }

推荐阅读