Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grid-core): Make a virtual table's viewport calculation band-friendly (T1154239) #3643

Merged

Conversation

VasilyStrelyaev
Copy link
Contributor

@VasilyStrelyaev VasilyStrelyaev commented Mar 22, 2023

This PR fixes an issue where header bands that stretch across several fixed columns are split during scrolling: https://supportcenter.devexpress.com/ticket/details/t1154239/reactive-grid-fixed-columns-are-duplicated-if-virtualtable-is-used.

The reason is that when the virtual table calculates the viewport to determine which columns to render, and fixed columns are beyond the regularly calculated viewport, the virtual table adds fixed columns explicitly. However, fixed columns are not merged into a single range but rather added as multiple ranges:

Here is the code that did it: https://github.com/DevExpress/devextreme-reactive/blob/master/packages/dx-grid-core/src/utils/virtual-table.ts#L22

However, bands cannot stretch through multiple viewport ranges, so they get split.

It looks like there is no special reason why adjacent ranges of the viewport cannot be merged together. So, I modified the method that adds fixed columns to the viewport, so that it now merges adjacent indexes into ranges (see my new tests). I aimed not to increase the algorithm's computational complexity as it runs on scroll.

You may notice that the algorithm can now merge both fixed and unfixed columns in a single range. This does not seem to be a problem and it does not prevent a border to appear between fixed and unfixed columns. That's because when splitting the header bands, the grid relies not only on the viewport ranges but also on "column chains", which do break between fixed and unfixed columns.

@VasilyStrelyaev VasilyStrelyaev changed the title fix(dx-grid-core): Make virtual table's viewport calculation band-friendly fix(grid-core): Make virtual table's viewport calculation band-friendly Mar 22, 2023
@VasilyStrelyaev VasilyStrelyaev changed the title fix(grid-core): Make virtual table's viewport calculation band-friendly fix(grid-core): Make virtual table's viewport calculation band-friendly (T1154239) Mar 22, 2023
}

if (acc.length && acc[acc.length - 1][1] === index - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add constant to describe meaning of: acc.length && acc[acc.length - 1][1] === index - 1

const isAdjacentToPreviousRange = previousRange && previousRange[1] === index - 1;

if (isAdjacentToPreviousRange) {
acc.pop();
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor you can replace pop and push to a single splice

@VasilyStrelyaev VasilyStrelyaev merged commit cf41706 into DevExpress:master Mar 23, 2023
8 checks passed
@VasilyStrelyaev VasilyStrelyaev changed the title fix(grid-core): Make virtual table's viewport calculation band-friendly (T1154239) fix(grid-core): Make a virtual table's viewport calculation band-friendly (T1154239) May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants