Steps to reproduce:
What behavior were you expecting to see?
Two sticky columns, correctly positioned and not moving when using the horizontal scrollbar.
What behavior did you actually see?
Looking at the code, it seems that cells' width is computed before actually being rendered. It causes an issue when setting the left css property
I'm having a similar problem. In my case, I'm supplying a variable set of columns which can be updated dynamically.
Stackblitz example here: https://stackblitz.com/edit/components-issue-dkllsa
If you click the "Toggle Pos Column" button, it will take the first column out of the column set, or put it back. The first time (removing the column), everything is fine. However, clicking it again to put it back leaves the second column pushed too far to the right.
The "Toggle Pos Column (delayed)" button leaves a short timeout between updating the column set and setting the stickiness of the columns. This option works perfectly.
Looking in the code, and adding some logpoints to src/cdk/table/sticky-styler.ts:updateStickyColumns() shows that when clicking the non-delayed button the new column seems to be pushed onto the tail end of the cellWidths (and consequently startPositions) arrays. Obviously the sticky position is then calculated incorrectly. The delayed sticky update happens after the columns have rendered, so works fine.
@ghusse That does look like the issue - thanks
Any more insight into this issue? @dickp solution used to work for Material 8, but in Material 10 I am getting the same issue again.
Most helpful comment
I'm having a similar problem. In my case, I'm supplying a variable set of columns which can be updated dynamically.
Stackblitz example here: https://stackblitz.com/edit/components-issue-dkllsa
If you click the "Toggle Pos Column" button, it will take the first column out of the column set, or put it back. The first time (removing the column), everything is fine. However, clicking it again to put it back leaves the second column pushed too far to the right.
The "Toggle Pos Column (delayed)" button leaves a short timeout between updating the column set and setting the stickiness of the columns. This option works perfectly.
Looking in the code, and adding some logpoints to src/cdk/table/sticky-styler.ts:updateStickyColumns() shows that when clicking the non-delayed button the new column seems to be pushed onto the tail end of the cellWidths (and consequently startPositions) arrays. Obviously the sticky position is then calculated incorrectly. The delayed sticky update happens after the columns have rendered, so works fine.