Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T1261532: DataGrid - FocusedRowChanged event isn't raised when the push API is used to remove the last row #28790

Open
wants to merge 1 commit into
base: 24_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading