有办法判断CellRangeRenderer处理的是多个表格中的哪个表格?

我目前是通过父属性的className来判断的:parent._scrollingContainer.className

cellRangeRenderer = (props: Object) => {
        const renderedCells = defaultCellRangeRenderer(props);
        const {
            columnStartIndex,
            columnStopIndex,
            parent,
        } = props;
        if (parent._scrollingContainer && parent._scrollingContainer.className.includes('grid-header') && columnStopIndex !== 0) {
            return [...renderedCells, ...this.props.cachedHeaderElements];
        }
        return renderedCells;
    }

我想知道是否有更简单的方法?

发布于 2020-12-09 16:44
共1个回答
UJ
游客uJLTPs

这里有个不那么复杂的办法:

class MyGrid extends Component {
  constructor(props) {
    super(props);
    this.multiGridRef = React.createRef();
  }

  renderCellRange = props => {
    const children = defaultCellRangeRenderer(props);

    if (props.parent === this.multiGridRef.current._bottomRightGrid) {
      // Operating on bottom right grid
    }

    return children;
  }

  render() {
    return <MultiGrid ref={this.multiGridRef} cellRangeRenderer={this.renderCellRange} />
   }
}
回答问题