Skip to content

Commit 4f06959

Browse files
authored
DataGrid: Fix the column headers scroll position reset in RTL mode with native scrolling (#35503)
Co-authored-by: Alyar <>
1 parent 439fba2 commit 4f06959

3 files changed

Lines changed: 149 additions & 2 deletions

File tree

‎e2e/testcafe-devextreme/tests/dataGrid/common/scrolling.ts‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,80 @@ test('Horizontal scrolling should work correctly in RTL mode with native scrolli
508508
await removeStylesheetRulesFromPage();
509509
});
510510

511+
test('Column headers should keep the scroll position after resizing a column in RTL mode with native scrolling', async (t) => {
512+
const dataGrid = new DataGrid('#container');
513+
const rowsScrollContainer = dataGrid.getScrollContainer();
514+
const headersScrollContainer = dataGrid.getHeadersScrollContainer();
515+
516+
await t
517+
.expect(dataGrid.isReady())
518+
.ok();
519+
520+
const initialScrollLeft = await dataGrid.getScrollLeft();
521+
522+
await dataGrid.scrollTo(t, { x: initialScrollLeft - 100 });
523+
524+
await t
525+
.expect(rowsScrollContainer.scrollLeft)
526+
.eql(-100)
527+
.expect(headersScrollContainer.scrollLeft)
528+
.eql(-100);
529+
530+
await dataGrid.resizeHeader(2, -30);
531+
532+
await t
533+
.expect(rowsScrollContainer.scrollLeft)
534+
.eql(-100)
535+
.expect(headersScrollContainer.scrollLeft)
536+
.eql(-100);
537+
}).before(async () => createWidget('dxDataGrid', {
538+
rtlEnabled: true,
539+
width: 500,
540+
dataSource: getData(5, 10),
541+
columnAutoWidth: true,
542+
allowColumnResizing: true,
543+
columnResizingMode: 'nextColumn',
544+
scrolling: {
545+
useNative: true,
546+
},
547+
}));
548+
549+
test('Column headers should keep the scroll position after repaint in RTL mode with native scrolling', async (t) => {
550+
const dataGrid = new DataGrid('#container');
551+
const rowsScrollContainer = dataGrid.getScrollContainer();
552+
const headersScrollContainer = dataGrid.getHeadersScrollContainer();
553+
554+
await t
555+
.expect(dataGrid.isReady())
556+
.ok();
557+
558+
const initialScrollLeft = await dataGrid.getScrollLeft();
559+
560+
await dataGrid.scrollTo(t, { x: initialScrollLeft - 100 });
561+
562+
await t
563+
.expect(rowsScrollContainer.scrollLeft)
564+
.eql(-100)
565+
.expect(headersScrollContainer.scrollLeft)
566+
.eql(-100);
567+
568+
await dataGrid.repaint();
569+
570+
await t
571+
.expect(rowsScrollContainer.scrollLeft)
572+
.eql(-100)
573+
.expect(headersScrollContainer.scrollLeft)
574+
.eql(-100);
575+
}).before(async () => createWidget('dxDataGrid', {
576+
rtlEnabled: true,
577+
width: 500,
578+
dataSource: getData(5, 10),
579+
columnAutoWidth: true,
580+
scrolling: {
581+
useNative: true,
582+
},
583+
}));
584+
511585
test('Column headers should have the correct scroll position after refreshing the data twice when RTL and virtual scrolling are enabled (T1333941)', async (t) => {
512586
const dataGrid = new DataGrid('#container');
513587

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {
2+
afterEach,
3+
beforeEach,
4+
describe,
5+
expect,
6+
it,
7+
jest,
8+
} from '@jest/globals';
9+
10+
import {
11+
afterTest,
12+
beforeTest,
13+
createDataGrid,
14+
} from '../../__tests__/__mock__/helpers/utils';
15+
16+
const createGrid = (rtlEnabled: boolean): ReturnType<typeof createDataGrid> => createDataGrid({
17+
rtlEnabled,
18+
dataSource: [{ id: 1, a: 'a', b: 'b' }],
19+
columns: ['a', 'b'],
20+
scrolling: {
21+
useNative: true,
22+
},
23+
});
24+
25+
describe('ColumnHeadersView horizontal scroll position', () => {
26+
beforeEach(beforeTest);
27+
afterEach(afterTest);
28+
29+
describe('when the headers are scrolled to a negative position in RTL', () => {
30+
it('should restore the position after the headers are rendered again', async () => {
31+
const { instance } = await createGrid(true);
32+
const columnHeadersView = instance.getView('columnHeadersView');
33+
34+
columnHeadersView.scrollTo({ left: -100 });
35+
36+
const scrollToSpy = jest.spyOn(columnHeadersView, 'scrollTo');
37+
38+
columnHeadersView.render();
39+
jest.runAllTimers();
40+
41+
expect(scrollToSpy).toHaveBeenCalledWith({ left: -100 });
42+
});
43+
44+
it('should restore the position after the headers are resized', async () => {
45+
const { instance } = await createGrid(true);
46+
const columnHeadersView = instance.getView('columnHeadersView');
47+
48+
columnHeadersView.scrollTo({ left: -100 });
49+
50+
const scrollToSpy = jest.spyOn(columnHeadersView, 'scrollTo');
51+
52+
columnHeadersView.resize();
53+
54+
expect(scrollToSpy).toHaveBeenCalledWith({ left: -100 });
55+
});
56+
});
57+
58+
describe('when the headers are scrolled to a positive position in LTR', () => {
59+
it('should restore the position after the headers are rendered again', async () => {
60+
const { instance } = await createGrid(false);
61+
const columnHeadersView = instance.getView('columnHeadersView');
62+
63+
columnHeadersView.scrollTo({ left: 100 });
64+
65+
const scrollToSpy = jest.spyOn(columnHeadersView, 'scrollTo');
66+
67+
columnHeadersView.render();
68+
jest.runAllTimers();
69+
70+
expect(scrollToSpy).toHaveBeenCalledWith({ left: 100 });
71+
});
72+
});
73+
});

‎packages/devextreme/js/__internal/grids/grid_core/views/m_columns_view.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class ColumnsView extends ColumnStateMixin(modules.View) {
205205
protected _columnChooserView!: ColumnChooserView;
206206

207207
public init() {
208-
this._scrollLeft = -1;
208+
this._scrollLeft = undefined;
209209
this._columnsController = this.getController('columns');
210210
this._dataController = this.getController('data');
211211
this.adaptiveColumnsController = this.getController('adaptiveColumns');
@@ -1077,7 +1077,7 @@ export class ColumnsView extends ColumnStateMixin(modules.View) {
10771077
protected updateScrollLeftPosition(): void {
10781078
const scrollLeft = this._scrollLeft;
10791079

1080-
if (scrollLeft >= 0) {
1080+
if (isDefined(scrollLeft)) {
10811081
this._scrollLeft = 0;
10821082
this.scrollTo({ left: scrollLeft });
10831083
}

0 commit comments

Comments
 (0)