I'm developing a data grid component based on react-virtualized. It's supposed to have a fixed header with resizable columns. I want the header to change its height according to the header cells content. I'm using CellMeasurer to calculate cells height and update height of the header.
The problem is that cell sizes are calculated after the cells are rendered (afaik), so I have to call forceUpdate inside of the header's render if height has been changed.
here is how render looks like (complete example is here):
render() {
const height = this._cache.rowHeight({ index: 0 });
console.log('render', height, this.props.sizes);
setTimeout(() => {
if (height !== this._cache.rowHeight({ index: 0 })) {
console.log('forceUpdate', this._cache.rowHeight({ index: 0 }))
this.forceUpdate()
}
}, 0)
return (
<Grid
ref={ref => this._grid = ref}
deferredMeasurementCache={this._cache}
width={1500}
height={height}
columnCount={5}
columnWidth={this.columnWidth}
rowCount={1}
rowHeight={this._cache.rowHeight}
cellRenderer={this.renderCell}
/>
);
}
so the question is how do I avoid forceUpdate? Is there a cleaner way to implement grid header with dynamic height using react-virtualized?