Skip to content

Commit 7673319

Browse files
authored
DataGrid: Fix the navigateToRow method when navigating down to the bottom row with virtual scrolling enabled (T1220800) (#33692)
Co-authored-by: Alyar <>
1 parent 2475ae9 commit 7673319

10 files changed

Lines changed: 91 additions & 2 deletions
Loading
Loading
29 Bytes
Loading
Loading
-32 Bytes
Loading
Loading
3 Bytes
Loading

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,3 +2115,82 @@ test('Horizontal scrollbar should not appear when columnHidingEnabled is true an
21152115
useNative: true,
21162116
},
21172117
}));
2118+
2119+
test('navigateToRow should scroll to the correct row with virtual scrolling (T1220800)', async (t) => {
2120+
const dataGrid = new DataGrid('#container');
2121+
const targetKey = 901;
2122+
2123+
await t.expect(dataGrid.isReady()).ok();
2124+
2125+
// act
2126+
await dataGrid.apiNavigateToRow(targetKey);
2127+
2128+
// assert
2129+
await t
2130+
.expect(dataGrid.isReady())
2131+
.ok()
2132+
.expect(dataGrid.getDataCells(0).nth(0).textContent)
2133+
.eql(String(targetKey));
2134+
2135+
const visibleRows = await dataGrid.apiGetVisibleRows();
2136+
2137+
await t.expect(visibleRows[0].key).eql(targetKey, `Row with key ${targetKey} should be the first visible row after navigation`);
2138+
}).before(async (t) => {
2139+
const initStore = ClientFunction(() => {
2140+
const getItems = (): Record<string, unknown>[] => {
2141+
const items: Record<string, unknown>[] = [];
2142+
for (let i = 0; i < 1000000; i += 1) {
2143+
items.push({
2144+
ID: i + 1,
2145+
Name: `Name ${i + 1}`,
2146+
Description: `Text text text text text text text text text text ${i + 1}`,
2147+
});
2148+
}
2149+
return items;
2150+
};
2151+
2152+
(window as any).myStore = new (window as any).DevExpress.data.ArrayStore({
2153+
key: 'ID',
2154+
data: getItems(),
2155+
});
2156+
});
2157+
2158+
await initStore.with({ boundTestRun: t })();
2159+
2160+
return createWidget('dxDataGrid', () => ({
2161+
dataSource: new (window as any).DevExpress.data.CustomStore({
2162+
key: 'ID',
2163+
loadMode: 'raw',
2164+
load(loadOptions) {
2165+
return new Promise((resolve) => {
2166+
(window as any).myStore.load(loadOptions).done((data) => {
2167+
resolve(data);
2168+
});
2169+
});
2170+
},
2171+
totalCount() {
2172+
return (window as any).myStore.totalCount();
2173+
},
2174+
}),
2175+
width: 900,
2176+
height: 250,
2177+
wordWrapEnabled: true,
2178+
showBorders: true,
2179+
scrolling: {
2180+
mode: 'virtual',
2181+
rowRenderingMode: 'virtual',
2182+
useNative: false,
2183+
},
2184+
paging: {
2185+
pageSize: 20,
2186+
},
2187+
columns: [
2188+
{
2189+
dataField: 'ID',
2190+
width: 90,
2191+
},
2192+
'Name',
2193+
'Description',
2194+
],
2195+
}));
2196+
});

packages/devextreme/js/__internal/grids/grid_core/virtual_scrolling/m_virtual_scrolling_core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class VirtualScrollController {
321321
}
322322
});
323323

324-
return Math.floor(offset + itemCount * this._viewportItemSize * this._sizeRatio);
324+
return offset + itemCount * this._viewportItemSize * this._sizeRatio;
325325
}
326326

327327
private getContentOffset(type) {

packages/testcafe-models/dataGrid/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,18 @@ export default class DataGrid extends GridCore {
190190
return this.getRowsView().find(`.${CLASS.row}`);
191191
}
192192

193+
getDataRows(): Selector {
194+
return this.getRows().filter(`.${CLASS.dataRow}`);
195+
}
196+
193197
getCells(): Selector {
194198
return this.getRowsView().find('td');
195199
}
196200

201+
getDataCells(rowIndex: number): Selector {
202+
return this.getDataRows().nth(rowIndex).find('td');
203+
}
204+
197205
getDataRow(index: number): DataRow {
198206
return new DataRow(this.element.find(`.${CLASS.dataRow}[aria-rowindex='${index + 1}']`), this.getName());
199207
}
@@ -962,8 +970,10 @@ export default class DataGrid extends GridCore {
962970
const isElementInRowsView = (element) => {
963971
const rowsViewRect = rowsViewElement[0].getBoundingClientRect();
964972
const elementRect = element.getBoundingClientRect();
973+
const tolerance = 1;
965974

966-
return elementRect.top >= rowsViewRect.top && elementRect.bottom <= rowsViewRect.bottom;
975+
return elementRect.top >= rowsViewRect.top - tolerance
976+
&& elementRect.bottom <= rowsViewRect.bottom + tolerance;
967977
};
968978
const rowElement = rowsViewElement.find('.dx-row-focused');
969979

0 commit comments

Comments
 (0)