Skip to content

Commit b3b7cb0

Browse files
authored
T1261532: DataGrid - FocusedRowChanged event isn't raised when the push API is used to remove the last row (#28792)
1 parent d15b009 commit b3b7cb0

File tree

2 files changed

+48
-5
lines changed
  • e2e/testcafe-devextreme/tests/dataGrid/focus
  • packages/devextreme/js/__internal/grids/grid_core/focus

2 files changed

+48
-5
lines changed

e2e/testcafe-devextreme/tests/dataGrid/focus/focus.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ test('DataGrid - FilterRow cell loses focus when focusedRowEnabled is true and e
242242
});
243243
});
244244

245+
test('DataGrid - FocusedRowChanged event isnt raised when the push API is used to remove the last row (T1261532)', async (t) => {
246+
const grid = new DataGrid(GRID_SELECTOR);
247+
248+
await t
249+
.expect(grid.option('focusedRowKey'))
250+
.eql(null)
251+
.expect(grid.option('focusedRowIndex'))
252+
.eql(-1);
253+
}).before(async () => createWidget('dxDataGrid', {
254+
dataSource: {
255+
store: {
256+
data: [
257+
{
258+
id: 1,
259+
name: 'Item 1 ',
260+
},
261+
],
262+
type: 'array',
263+
key: 'id',
264+
},
265+
reshapeOnPush: true,
266+
},
267+
keyExpr: 'id',
268+
showBorders: true,
269+
focusedRowEnabled: true,
270+
focusedRowKey: 1,
271+
onInitialized(e) {
272+
e.component?.getDataSource().store().push([{ type: 'remove', key: 1 }]);
273+
},
274+
}));
275+
245276
['onFocusedRowChanged', 'onFocusedRowChanging'].forEach((event) => {
246277
test(`Focus should be preserved on datagrid when rowsview repaints in ${event} event (T1224663)`, async (t) => {
247278
const dataGrid = new DataGrid('#container');

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,28 @@ export class FocusController extends core.ViewController {
8282
if (!this.option('focusedRowEnabled')) {
8383
return;
8484
}
85+
const isEmptyData = this.getDataController().isEmpty();
86+
const currentIndex = this._getCurrentFocusRowIndex(isEmptyData, index);
8587

86-
index = index !== undefined ? index : this.option('focusedRowIndex');
87-
88-
if (index < 0) {
89-
if (this.isAutoNavigateToFocusedRow()) {
88+
if (currentIndex < 0) {
89+
if (isEmptyData || this.isAutoNavigateToFocusedRow()) {
9090
this._resetFocusedRow();
9191
}
9292
} else {
93-
this._focusRowByIndexCore(index, operationTypes);
93+
this._focusRowByIndexCore(currentIndex, operationTypes);
94+
}
95+
}
96+
97+
private _getCurrentFocusRowIndex(isEmptyData, index?): number {
98+
let currentIndex = index;
99+
if (currentIndex === undefined) {
100+
if (isEmptyData) {
101+
currentIndex = -1;
102+
} else {
103+
currentIndex = this.option('focusedRowIndex');
104+
}
94105
}
106+
return currentIndex;
95107
}
96108

97109
private _focusRowByIndexCore(index, operationTypes) {

0 commit comments

Comments
 (0)