@@ -20,12 +20,12 @@ async function getRightScrollOffset(dataGrid: DataGrid): Promise<number> {
2020 return maxHorizontalOffset - scrollLeft;
2121}
2222
23- function getData(rowCount, colCount): Record<string, string>[] {
23+ function getData(rowCount: number , colCount: number ): Record<string, string>[] {
2424 const items: Record<string, string>[] = [];
2525 for (let i = 0; i < rowCount; i += 1) {
2626 const item: Record<string, string> = {};
2727 for (let j = 0; j < colCount; j += 1) {
28- item[`field_${i}_${ j}`] = `val_${i}_${j}`;
28+ item[`field_${j}`] = `val_${i}_${j}`;
2929 }
3030 items.push(item);
3131 }
@@ -1824,3 +1824,62 @@ test('DataGrid - Scrolling position is reset to far right on an attempt to scrol
18241824 enabled: false,
18251825 },
18261826}));
1827+
1828+ [true, false].forEach((nativeScroll) => {
1829+ type TestCaseWindow = typeof window & { dataGridScrollableEventValues?: number[] };
1830+
1831+ test(
1832+ `Should not scroll back on top with virtual scrolling and adaptive master detail (nativeScroll: ${nativeScroll}) [T1278804]`,
1833+ async (t) => {
1834+ // NOTE: idx + 1 logic inside POM
1835+ const adaptiveCellIdx = 101;
1836+ const scrollValuesThreshold = 100;
1837+
1838+ const dataGrid = new DataGrid('#container');
1839+ const firstRow = dataGrid.getDataRow(0);
1840+ const firstDataCell = firstRow.getDataCell(0);
1841+ const adaptiveCell = firstRow.getCommandCell(adaptiveCellIdx);
1842+ const scrollContainer = dataGrid.getScrollContainer();
1843+
1844+ await t
1845+ .click(firstDataCell.element)
1846+ .click(adaptiveCell.element);
1847+
1848+ await t
1849+ .scroll(scrollContainer, 0, 1000)
1850+ .scroll(scrollContainer, 0, 1000);
1851+
1852+ const scrollOffsets = await t
1853+ .eval(() => (window as TestCaseWindow).dataGridScrollableEventValues) as number[];
1854+
1855+ const hasSmallScrollValues = scrollOffsets.some((offset) => offset < scrollValuesThreshold);
1856+ await t.expect(hasSmallScrollValues).notOk();
1857+ },
1858+ ).before(async () => {
1859+ await createWidget('dxDataGrid', {
1860+ dataSource: getData(3, 100).map((item, idx) => ({ ...item, id: idx })),
1861+ keyExpr: 'id',
1862+ columnHidingEnabled: true,
1863+ focusedRowEnabled: true,
1864+ scrolling: {
1865+ mode: 'virtual',
1866+ useNative: nativeScroll,
1867+ },
1868+ onContentReady: ({ component }) => {
1869+ const testWindow = window as TestCaseWindow;
1870+
1871+ component.getScrollable().on('scroll', ({ scrollOffset: { top } }) => {
1872+ if (!Array.isArray(testWindow.dataGridScrollableEventValues)) {
1873+ testWindow.dataGridScrollableEventValues = [];
1874+ }
1875+
1876+ testWindow.dataGridScrollableEventValues.push(top);
1877+ });
1878+ },
1879+ width: 400,
1880+ height: 400,
1881+ });
1882+ }).after(async (t) => t.eval(() => {
1883+ delete (window as TestCaseWindow).dataGridScrollableEventValues;
1884+ }));
1885+ });
0 commit comments