KEMBAR78
fix: update horizontal scroll position on data change by ugur-vaadin · Pull Request #10192 · vaadin/web-components · GitHub
Skip to content

Conversation

@ugur-vaadin
Copy link
Contributor

Description

When the data changes but there is no resize or scroll, the column widths are not recalculated with a new scroll position. On Windows, this leads to frozen-to-end columns not properly moved to the end, displaying data from other columns where the scroll bar was previously located.

This PR updates horizontal scroll position when the data changes. This makes sure that the frozen-to-end columns are always located at the end, even when there is no resize or scroll.

Fixes vaadin/flow-components#6666.

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/contributing/pr
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

// Updating data can change the visibility of the scroll bar. Therefore, the scroll position
// has to be recalculated.
requestAnimationFrame(() => {
this.__updateHorizontalScrollPosition();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a resize observer on the table element:

new ResizeObserver(() =>
setTimeout(() => {
this.__updateColumnsBodyContentHidden();
}),
).observe(this.$.table);

Adding the scroll position update there also seems to work and might cover other scenarios as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I hadn't noticed the table resize observer. Updated the fix to call the update on table resize. Also updated the test and simplified it a little bit.

@sonarqubecloud
Copy link

@ugur-vaadin ugur-vaadin merged commit a3876e6 into main Sep 23, 2025
9 checks passed
@ugur-vaadin ugur-vaadin deleted the fix-update-horizontal-scroll-position-on-data-change branch September 23, 2025 06:39
vaadin-bot pushed a commit that referenced this pull request Sep 23, 2025
* fix: update horizontal scroll position on data change

* refactor: update scroll position on table resize
vaadin-bot pushed a commit that referenced this pull request Sep 23, 2025
* fix: update horizontal scroll position on data change

* refactor: update scroll position on table resize
web-padawan pushed a commit that referenced this pull request Sep 23, 2025
Co-authored-by: Ugur Saglam <106508695+ugur-vaadin@users.noreply.github.com>
web-padawan pushed a commit that referenced this pull request Sep 23, 2025
Co-authored-by: Ugur Saglam <106508695+ugur-vaadin@users.noreply.github.com>
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 25.0.0-alpha12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grid frozen-at-end-column position isn't refreshed correctly when Grid items change

3 participants