Skip to content

Commit

Permalink
T1261532: DataGrid - FocusedRowChanged event isn't raised when the pu…
Browse files Browse the repository at this point in the history
…sh API is used to remove the last row (#28687)
  • Loading branch information
Raushen authored Jan 21, 2025
1 parent 52c5092 commit 485c8dc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
31 changes: 31 additions & 0 deletions e2e/testcafe-devextreme/tests/dataGrid/focus/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,37 @@ test('DataGrid - FilterRow cell loses focus when focusedRowEnabled is true and e
});
});

test('DataGrid - FocusedRowChanged event isnt raised when the push API is used to remove the last row (T1261532)', async (t) => {
const grid = new DataGrid(GRID_SELECTOR);

await t
.expect(grid.option('focusedRowKey'))
.eql(null)
.expect(grid.option('focusedRowIndex'))
.eql(-1);
}).before(async () => createWidget('dxDataGrid', {
dataSource: {
store: {
data: [
{
id: 1,
name: 'Item 1 ',
},
],
type: 'array',
key: 'id',
},
reshapeOnPush: true,
},
keyExpr: 'id',
showBorders: true,
focusedRowEnabled: true,
focusedRowKey: 1,
onInitialized(e) {
e.component?.getDataSource().store().push([{ type: 'remove', key: 1 }]);
},
}));

['onFocusedRowChanged', 'onFocusedRowChanging'].forEach((event) => {
test(`Focus should be preserved on datagrid when rowsview repaints in ${event} event (T1224663)`, async (t) => {
const dataGrid = new DataGrid('#container');
Expand Down
22 changes: 17 additions & 5 deletions packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,28 @@ export class FocusController extends core.ViewController {
if (!this.option('focusedRowEnabled')) {
return;
}
const isEmptyData = this.getDataController().isEmpty();
const currentIndex = this._getCurrentFocusRowIndex(isEmptyData, index);

index = index !== undefined ? index : this.option('focusedRowIndex');

if (index < 0) {
if (this.isAutoNavigateToFocusedRow()) {
if (currentIndex < 0) {
if (isEmptyData || this.isAutoNavigateToFocusedRow()) {
this._resetFocusedRow();
}
} else {
this._focusRowByIndexCore(index, operationTypes);
this._focusRowByIndexCore(currentIndex, operationTypes);
}
}

private _getCurrentFocusRowIndex(isEmptyData, index?): number {
let currentIndex = index;
if (currentIndex === undefined) {
if (isEmptyData) {
currentIndex = -1;
} else {
currentIndex = this.option('focusedRowIndex');
}
}
return currentIndex;
}

private _focusRowByIndexCore(index, operationTypes) {
Expand Down

0 comments on commit 485c8dc

Please sign in to comment.