【发布时间】:2019-07-16 23:57:24
【问题描述】:
我正在使用 react-virtualized 来渲染我的表格。是否可以用自定义组件替换默认的 Column 组件?我不断收到此错误
Failed prop type: Table only accepts children of type Column
【问题讨论】:
我正在使用 react-virtualized 来渲染我的表格。是否可以用自定义组件替换默认的 Column 组件?我不断收到此错误
Failed prop type: Table only accepts children of type Column
【问题讨论】:
是的,当然,你可以通过使用 Column 中的 cellRenderer 属性来实现,这是一个回调函数,它会给你一堆参数,你需要返回将在单元格中呈现的自定义组件
<Column key={column.dataKey + column.label + index} dataKey={column.dataKey}
cellRenderer={
({ cellData, rowIndex, dataKey }) => (
<CheckBox
cellData={cellData}
changeCheckBox={changeCheckBoxHandler.bind(
this,
rowIndex,
dataKey
)}
/>
)
}/>
您可以在此处找到详细信息。 https://github.com/bvaughn/react-virtualized/blob/master/docs/Column.md#cellrenderer
【讨论】:
您为什么要这样做?您必须使用Column 组件来定义每一列,然后您可以在每个Column 中呈现您想要的任何内容。
【讨论】: