Skip to content

Commit b99bbb7

Browse files
authored
DataGrid: Fix duplicate summary groups with alignByColumn enabled for grouped column with showWhenGrouped enabled (T1300738) (#30991)
1 parent 14f4306 commit b99bbb7

File tree

6 files changed

+129
-2
lines changed

6 files changed

+129
-2
lines changed
29.7 KB
Loading

e2e/testcafe-devextreme/tests/dataGrid/common/summary.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import url from '../../../helpers/getPageUrl';
44
import { createWidget } from '../../../helpers/createWidget';
55

66
fixture.disablePageReloads`Summary`
7-
.page(url(__dirname, '../../../container.html'));
7+
.page(url(__dirname, '../../container.html'));
88

99
test('Group footer summary should be focusable', async (t) => {
1010
const dataGrid = new DataGrid('#container');
@@ -146,3 +146,53 @@ test('Group footer navigation should work without keyboard trap', async (t) => {
146146
],
147147
},
148148
}));
149+
150+
test('The group summary should be displayed next to the grouped value when the grouped column has the showWhenGrouped option enabled', async (t) => {
151+
// arrange, act
152+
const dataGrid = new DataGrid('#container');
153+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
154+
155+
// assert
156+
await t
157+
.expect(dataGrid.isReady())
158+
.ok()
159+
.expect(await takeScreenshot('group-summary-when-grouped-column-has-showWhenGrouped.png', dataGrid.element))
160+
.ok()
161+
.expect(compareResults.isValid())
162+
.ok(compareResults.errorMessages());
163+
}).before(async () => createWidget('dxDataGrid', {
164+
dataSource: [
165+
{
166+
id: 1, value1: 1, value2: 2, value3: 3,
167+
},
168+
{
169+
id: 2, value1: 4, value2: 5, value3: 6,
170+
},
171+
{
172+
id: 3, value1: 7, value2: 8, value3: 9,
173+
},
174+
{
175+
id: 4, value1: 10, value2: 11, value3: 12,
176+
},
177+
],
178+
columns: [
179+
'id',
180+
'value1',
181+
'value2',
182+
{
183+
dataField: 'value3',
184+
groupIndex: 0,
185+
showWhenGrouped: true,
186+
},
187+
],
188+
summary: {
189+
groupItems: [
190+
{
191+
column: 'value3',
192+
summaryType: 'count',
193+
displayFormat: '{0} VALUE3 GROUP COUNT',
194+
alignByColumn: true,
195+
},
196+
],
197+
},
198+
}));

packages/devextreme/js/__internal/grids/data_grid/summary/m_summary.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type { RowsView } from '../../grid_core/views/m_rows_view';
2323
import AggregateCalculator from '../m_aggregate_calculator';
2424
import gridCore from '../m_core';
2525
import dataSourceAdapterProvider from '../m_data_source_adapter';
26+
import { getSummaryCellIndex } from './utils';
2627

2728
const DATAGRID_TOTAL_FOOTER_CLASS = 'dx-datagrid-total-footer';
2829
const DATAGRID_SUMMARY_ITEM_CLASS = 'dx-datagrid-summary-item';
@@ -538,10 +539,12 @@ const data = (Base: ModuleType<DataController>) => class SummaryDataControllerEx
538539
}
539540
}
540541
});
542+
541543
if (!isEmptyObject(summaryCellsByColumns)) {
542544
visibleColumns.forEach((column, visibleIndex) => {
543545
const prevColumn = visibleColumns[visibleIndex - 1];
544-
const columnIndex = isGroupRow && (prevColumn?.command === 'expand' || column.command === 'expand') ? prevColumn?.index : column.index;
546+
const columnIndex = getSummaryCellIndex(column, prevColumn, isGroupRow);
547+
545548
summaryCells.push(summaryCellsByColumns[columnIndex] || []);
546549
});
547550
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { isDefined } from '@js/core/utils/type';
2+
import type { Column } from '@ts/grids/grid_core/columns_controller/m_columns_controller';
3+
4+
export function getSummaryCellIndex(
5+
column: Column,
6+
prevColumn?: Column,
7+
isGroupRow = false,
8+
): number {
9+
const cellIndex = column.index ?? -1;
10+
11+
if (!isGroupRow) {
12+
return cellIndex;
13+
}
14+
15+
if (prevColumn?.type === 'groupExpand' || column.type === 'groupExpand') {
16+
return prevColumn?.index ?? -1;
17+
}
18+
19+
return !isDefined(column.groupIndex) ? cellIndex : -1;
20+
}

packages/devextreme/js/__internal/grids/grid_core/columns_controller/m_columns_controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {
8585
export interface Column extends ColumnBase {
8686
parseValue: (text: string) => unknown;
8787
index?: number;
88+
groupIndex?: number;
8889
type?: string;
8990
visibleWidth?: string | number;
9091
}

packages/devextreme/testing/tests/DevExpress.exporter/exceljsParts/exceljs.dataGrid.tests.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,59 @@ const moduleConfig = {
33183318
});
33193319
});
33203320

3321+
// T1300738
3322+
QUnit.test('Grouping - 1 level & 3 columns - col_3.showWhenGrouped: true, summary_col_3.alignByColumn: true', function(assert) {
3323+
const done = assert.async();
3324+
const ds = [
3325+
{ f1: 'f1_1', f2: 'f2_1', f3: 'f3_1' },
3326+
];
3327+
const dataGrid = $('#dataGrid').dxDataGrid({
3328+
columns: [
3329+
{ dataField: 'f1', caption: 'f1', width: 100 },
3330+
{ dataField: 'f2', caption: 'f2', width: 150 },
3331+
{ dataField: 'f3', caption: 'f3', width: 200, groupIndex: 0, showWhenGrouped: true }
3332+
],
3333+
summary: {
3334+
groupItems: [
3335+
{
3336+
column: 'f3',
3337+
summaryType: 'count',
3338+
displayFormat: '{0} F3 GROUP COUNT',
3339+
alignByColumn: true,
3340+
}
3341+
]
3342+
},
3343+
dataSource: ds,
3344+
showColumnHeaders: false,
3345+
loadingTimeout: null
3346+
}).dxDataGrid('instance');
3347+
3348+
const expectedCells = [
3349+
[
3350+
{ excelCell: { value: 'f3: f3_1 (1 F3 GROUP COUNT)', alignment: alignLeftTopNoWrap, font: { bold: true } }, gridCell: { rowType: 'group', groupIndex: 0, column: dataGrid.columnOption(2), value: 'f3_1', groupSummaryItems: [{ name: undefined, value: 1 }] } },
3351+
{ excelCell: { value: null }, gridCell: { value: undefined, rowType: 'group', groupIndex: 0, column: dataGrid.columnOption(1) } },
3352+
{ excelCell: { value: null }, gridCell: { value: undefined, rowType: 'group', groupIndex: 0, column: dataGrid.columnOption(2) } },
3353+
], [
3354+
{ excelCell: { value: 'f1_1', alignment: alignLeftTopNoWrap }, gridCell: { rowType: 'data', data: ds[0], column: dataGrid.columnOption(0) } },
3355+
{ excelCell: { value: 'f2_1', alignment: alignLeftTopNoWrap }, gridCell: { rowType: 'data', data: ds[0], column: dataGrid.columnOption(1) } },
3356+
{ excelCell: { value: 'f3_1', alignment: alignLeftTopNoWrap }, gridCell: { rowType: 'data', data: ds[0], column: dataGrid.columnOption(2) } },
3357+
]
3358+
];
3359+
3360+
helper._extendExpectedCells(expectedCells, topLeft);
3361+
3362+
exportDataGrid(getOptions(this, dataGrid, expectedCells)).then((cellRange) => {
3363+
helper.checkRowAndColumnCount({ row: 2, column: 3 }, { row: 2, column: 3 }, topLeft);
3364+
helper.checkAutoFilter(autoFilterEnabled, null);
3365+
helper.checkCellStyle(expectedCells);
3366+
helper.checkValues(expectedCells);
3367+
helper.checkMergeCells(expectedCells, topLeft);
3368+
helper.checkOutlineLevel([0, 1], topLeft.row);
3369+
helper.checkCellRange(cellRange, { row: 2, column: 3 }, topLeft);
3370+
done();
3371+
});
3372+
});
3373+
33213374
[true, false].forEach((masterDetailEnabled) => {
33223375
QUnit.test(`Grouping - 1 level - 1 summary group node, masterDetail.enabled: ${masterDetailEnabled}`, function(assert) {
33233376
const done = assert.async();

0 commit comments

Comments
 (0)