react-table custom cell component that references several row properties

不想你离开。 提交于 2019-12-04 20:00:32

问题


I need to implement table sorting by column so am rewriting my react table component using react-table's ReactTable component.

One of table cells will contain a link and needs to access more one row property. So far, the link column code looks like:

{
    Header: "Name",
    accessor: "name",
    Cell: cellInfo => (
        <Link className="scenarioDetailLink"
              to={cellInfo.row.linkDestination}
              id={cellInfo.row.linkName}>{cellInfo.row.name}</Link>
    )
},

It results in elements like this:

The generated anchor element is missing id and href properties. What am I doing wrong.


回答1:


It turned out I needed to use cellInfo.original rather than cellInfo.row. When you provide a Cell renderer you should use cellInfo.original to get at all of your row data (especially if you aren’t showing that data as columns). The row only has what is displayed in the table.



来源:https://stackoverflow.com/questions/45968791/react-table-custom-cell-component-that-references-several-row-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!