palantir/blueprint
View on GitHubTable2 `columnWidths` prop is not working as expected
Open
#5778 opened on Nov 30, 2022
P2Package: tableType: bughelp wanted
Description
Environment
"@blueprintjs/table": "4.7.9"
Code Sandbox
Link to a minimal repro: demo
Steps to reproduce
Checkout the demo code:
- initially
colWidthscontainsnullvalue for the 1st column width and 230 for the 2nd column; - further we have an effect which updates
colWidths: we set 400 width for the 1st column, 2nd column remains the same; - finally we have a toggle which allows to set both columns' widths to 300;
Now follow these steps:
- Load the page
- Click the "Set all cols 300 width" button
- Click "Set all cols 300 width" again
Actual behavior
- Once loaded column widths are: some "default" value for 1st col and 230 for the 2nd one
- Upon 1st click column widths are: 400 and 230
- Upon 2nd click column widths are: 300 and 300
Expected behavior
- Once loaded, column width should be 400 and 230 due to effect we ran on mount
- Upon 1st click on "Set all cols 300 width" rendered columns should have 300 and 300 widths
Possible solution
Adding colWidths (which is passed via columnWidths prop) to cellRendererDependencies "fixes" the issue;
Additional observations
- It seems like
Table2uses previous value ofcolumnWidths, hence lagging the most recent value; - If you try scrolling the table, it "forces" table to re-render with proper column widths;
P.s. this separate issue creation was requested in #5264.