Skip to content

Commit c9bb7b7

Browse files
authored
T1280020 - DataGrid - The 'row' parameter in the FocusedRowChanged event refers to a non-focused row if the grid height is small (DevExpress#30786)
1 parent 6caa234 commit c9bb7b7

File tree

2 files changed

+40
-8
lines changed
  • e2e/testcafe-devextreme/tests/dataGrid/common
  • packages/devextreme/js/__internal/grids/grid_core/focus

2 files changed

+40
-8
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,32 @@ test('DataGrid - Scrolling position is reset to far right on an attempt to scrol
18251825
},
18261826
}));
18271827

1828+
// T1280020
1829+
test('DataGrid - The "row" parameter in the FocusedRowChanged event refers to a non-focused row if the grid height is small', async (t) => {
1830+
const dataGrid = new DataGrid('#container');
1831+
const otherContainer = Selector('#otherContainer');
1832+
1833+
await dataGrid.apiOption('focusedRowKey', '2');
1834+
await t.expect(otherContainer.innerText).eql('2');
1835+
1836+
await dataGrid.apiOption('focusedRowKey', '0');
1837+
await t.expect(otherContainer.innerText).eql('0');
1838+
}).before(async () => createWidget('dxDataGrid', {
1839+
height: 70,
1840+
dataSource: [
1841+
{ id: '0' },
1842+
{ id: '1' },
1843+
{ id: '2' },
1844+
],
1845+
scrolling: { mode: 'virtual' },
1846+
keyExpr: 'id',
1847+
focusedRowEnabled: true,
1848+
onFocusedRowChanged(e) {
1849+
const data = e.row?.data;
1850+
$('#otherContainer').text(data.id);
1851+
},
1852+
}));
1853+
18281854
[true, false].forEach((nativeScroll) => {
18291855
type TestCaseWindow = typeof window & { dataGridScrollableEventValues?: number[] };
18301856

packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable max-classes-per-file */
22
import $ from '@js/core/renderer';
33
import { equalByValue } from '@js/core/utils/common';
4-
import { Deferred, when } from '@js/core/utils/deferred';
4+
import { Deferred, type DeferredObj, when } from '@js/core/utils/deferred';
55
import { each } from '@js/core/utils/iterator';
66
import { isBoolean, isDefined } from '@js/core/utils/type';
77

@@ -53,8 +53,9 @@ export class FocusController extends core.ViewController {
5353
return;
5454
}
5555

56-
this._focusRowByKey(value);
57-
this.getKeyboardController()._fireFocusedRowChanged();
56+
this._focusRowByKey(value).done(() => {
57+
this.getKeyboardController()._fireFocusedRowChanged();
58+
});
5859
args.handled = true;
5960
break;
6061

@@ -166,12 +167,14 @@ export class FocusController extends core.ViewController {
166167
}
167168
}
168169

169-
private _focusRowByKey(key) {
170+
private _focusRowByKey(
171+
key: any,
172+
): DeferredObj<number | unknown> {
170173
if (!isDefined(key)) {
171174
this._resetFocusedRow();
172-
} else {
173-
this._navigateToRow(key, true);
175+
return Deferred().resolve();
174176
}
177+
return this._navigateToRow(key, true);
175178
}
176179

177180
public _resetFocusedRow() {
@@ -205,10 +208,13 @@ export class FocusController extends core.ViewController {
205208
if (!this.isAutoNavigateToFocusedRow()) {
206209
this.option('focusedRowIndex', -1);
207210
}
208-
return this._navigateToRow(key);
211+
return this._navigateToRow(key, false);
209212
}
210213

211-
public _navigateToRow(key, needFocusRow?) {
214+
public _navigateToRow(
215+
key: any,
216+
needFocusRow: boolean,
217+
): DeferredObj<number> {
212218
const that = this;
213219
const isAutoNavigate = that.isAutoNavigateToFocusedRow();
214220
// @ts-expect-error

0 commit comments

Comments
 (0)