Skip to content

Commit 7f4d2b3

Browse files
authored
DataGrid - Fix focusedRowKey with grouping, when grouped by 'null' - T1282925 (DevExpress#30643)
1 parent e8ce638 commit 7f4d2b3

File tree

7 files changed

+78
-11
lines changed

7 files changed

+78
-11
lines changed
8.13 KB
Loading
7.95 KB
Loading
8.72 KB
Loading
7.93 KB
Loading
Loading

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
12
import { ClientFunction } from 'testcafe';
23
import DataGrid from 'devextreme-testcafe-models/dataGrid';
34
import url from '../../../../../helpers/getPageUrl';
@@ -919,3 +920,70 @@ test('It is possible to focus row that was added via push method if previously r
919920
},
920921
],
921922
}));
923+
924+
[null, undefined, -1, 'test'].forEach((groupValue) => {
925+
test(`Group should expand when focusedRowKey is set - group: ${groupValue}`, async (t) => {
926+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
927+
const dataGrid = new DataGrid('#container');
928+
929+
await dataGrid.apiOption('focusedRowKey', 1);
930+
931+
await takeScreenshot(`focused-row_under_group=${groupValue}.png`, dataGrid.element);
932+
933+
await t
934+
.expect(compareResults.isValid())
935+
.ok(compareResults.errorMessages());
936+
}).before(async () => createWidget('dxDataGrid', {
937+
dataSource: [
938+
{ id: 1, group: groupValue, name: 'Item 1' },
939+
{ id: 2, group: groupValue, name: 'Item 2' },
940+
{ id: 3, group: 'A', name: 'Item 3' },
941+
{ id: 4, group: 'A', name: 'Item 4' },
942+
],
943+
keyExpr: 'id',
944+
grouping: {
945+
autoExpandAll: false,
946+
},
947+
columns: [
948+
{ dataField: 'id' },
949+
{ dataField: 'group', groupIndex: 0 },
950+
{ dataField: 'name' },
951+
],
952+
height: 400,
953+
focusedRowEnabled: true,
954+
}));
955+
});
956+
957+
test('Group should expand when focusedRowKey is set and data items have \'items\' property', async (t) => {
958+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
959+
const dataGrid = new DataGrid('#container');
960+
961+
await dataGrid.apiOption('focusedRowKey', 1);
962+
963+
await takeScreenshot('focused-row_under_group_when_data-items_have_items-property.png', dataGrid.element);
964+
965+
await t
966+
.expect(compareResults.isValid())
967+
.ok(compareResults.errorMessages());
968+
}).before(async () => createWidget('dxDataGrid', {
969+
dataSource: [
970+
{
971+
id: 1, group: 'A', name: 'Item 1', items: 1,
972+
},
973+
{
974+
id: 2, group: 'A', name: 'Item 2', items: 2,
975+
},
976+
],
977+
keyExpr: 'id',
978+
grouping: {
979+
autoExpandAll: false,
980+
},
981+
columns: [
982+
{ dataField: 'id' },
983+
{ dataField: 'group', groupIndex: 0 },
984+
{ dataField: 'name' },
985+
{ dataField: 'items' },
986+
],
987+
height: 400,
988+
focusedRowEnabled: true,
989+
}));

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,15 @@ const data = (Base: DataControllerBase) => class FocusDataControllerExtender ext
5656
return true;
5757
}
5858

59-
private _getGroupPath(groupItem, groupCount) {
59+
private _getGroupPath(groupItems, groupCount): any[] {
6060
const groupPath: any[] = [];
61-
let items = [groupItem];
61+
let groupItem = groupItems[0];
6262

63-
while (items && items[0] && groupCount) {
64-
const item = items[0];
65-
if (item.key !== undefined) {
66-
groupPath.push(item.key);
67-
}
68-
items = item.items;
69-
groupCount--;
63+
while (groupItem && groupPath.length < groupCount) {
64+
groupPath.push(groupItem.key);
65+
groupItem = groupItem.items?.[0];
7066
}
67+
7168
return groupPath;
7269
}
7370

@@ -114,11 +111,13 @@ const data = (Base: DataControllerBase) => class FocusDataControllerExtender ext
114111
filter: that._concatWithCombinedFilter(filter),
115112
group,
116113
}).done((data) => {
117-
if (!data || data.length === 0 || !isDefined(data[0].key) || data[0].key === -1) {
114+
const hasData = isDefined(data) && data.length > 0;
115+
116+
if (!hasData) {
118117
return deferred.resolve(-1).promise();
119118
}
120119

121-
const groupPath = that._getGroupPath(data[0], group.length);
120+
const groupPath = that._getGroupPath(data, group.length);
122121

123122
that._expandGroupByPath(that, groupPath, 0).done(() => {
124123
that._calculateExpandedRowGlobalIndex(deferred, key, groupPath, group);

0 commit comments

Comments
 (0)