Skip to content

Commit

Permalink
T1261532
Browse files Browse the repository at this point in the history
  • Loading branch information
Raushen committed Jan 8, 2025
1 parent 369219b commit eaf1d64
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
38 changes: 37 additions & 1 deletion e2e/testcafe-devextreme/tests/dataGrid/focus/focus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DataGrid from 'devextreme-testcafe-models/dataGrid';
import { ClientFunction } from 'testcafe';
import { ClientFunction, Selector } from 'testcafe';
import FilterTextBox from 'devextreme-testcafe-models/dataGrid/editors/filterTextBox';
import { createWidget } from '../../../helpers/createWidget';
import url from '../../../helpers/getPageUrl';
Expand Down Expand Up @@ -240,3 +240,39 @@ 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) => {
await t
.expect(Selector('#otherContainer').innerText)
.eql('Success');
}).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: function(e) {
e.component?.getDataSource().store().push([{ type: "remove", key: 1 }]);
},
onFocusedRowChanged: function(e) {
const key = e.component.option("focusedRowKey");
const index = e.component.option("focusedRowIndex");
debugger;

if(key === null && index === -1) {
$('#otherContainer').text('Success');
}
}
}));
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 eaf1d64

Please sign in to comment.