Skip to content

Commit 1c7b689

Browse files
authored
DataGrid – Resize indicator is moved when resizing a grouped column if showWhenGrouped is set to true (T1314667) (#31877)
1 parent f276d85 commit 1c7b689

File tree

3 files changed

+81
-13
lines changed

3 files changed

+81
-13
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,55 @@ test('column separator should starts from the parent', async (t) => {
7272
columns: ['GDP_Total', 'Population_Urban'],
7373
}, 'Area'],
7474
}));
75+
76+
// T1314667
77+
test('DataGrid – Resize indicator is moved when resizing a grouped column if showWhenGrouped is set to true', async (t) => {
78+
const dataGrid = new DataGrid('#container');
79+
80+
await t.expect(dataGrid.isReady()).ok();
81+
82+
await dataGrid.resizeHeader(3, 30, false);
83+
84+
await t
85+
.expect(dataGrid.getHeaders().getHeaderRow(1).getHeaderCell(0).element.clientWidth)
86+
.within(128, 130);
87+
}).before(async () => {
88+
await createWidget('dxDataGrid', {
89+
dataSource: [{
90+
ID: 1,
91+
Country: 'Brazil',
92+
Area: 8515767,
93+
Population_Urban: 0.85,
94+
Population_Rural: 0.15,
95+
Population_Total: 205809000,
96+
}],
97+
keyExpr: 'ID',
98+
allowColumnResizing: true,
99+
columnResizingMode: 'widget',
100+
width: 500,
101+
columns: [
102+
{
103+
dataField: 'ID',
104+
fixed: true,
105+
allowReordering: false,
106+
width: 50,
107+
},
108+
109+
{
110+
caption: 'Population',
111+
columns: [
112+
{
113+
dataField: 'Country',
114+
showWhenGrouped: true,
115+
width: 100,
116+
groupIndex: 0,
117+
},
118+
{ dataField: 'Area' },
119+
{ dataField: 'Population_Total' },
120+
{ dataField: 'Population_Urban' },
121+
{ dataField: 'Population_Rural' },
122+
],
123+
},
124+
],
125+
});
126+
});

packages/devextreme/js/__internal/grids/grid_core/column_headers/m_column_headers.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { dxElementWrapper } from '@js/core/renderer';
55
import $ from '@js/core/renderer';
66
import { Deferred } from '@js/core/utils/deferred';
77
import { extend } from '@js/core/utils/extend';
8-
import { each } from '@js/core/utils/iterator';
98
import { getHeight } from '@js/core/utils/size';
109
import { isDefined } from '@js/core/utils/type';
1110
import { ColumnContextMenuMixin } from '@ts/grids/grid_core/context_menu/m_column_context_menu_mixin';
@@ -483,25 +482,33 @@ export class ColumnHeadersView extends ColumnContextMenuMixin(ColumnsView) {
483482
}
484483

485484
public getColumnElements(index?, bandColumnIndex?) {
486-
const that = this;
487485
let $cellElement;
488-
const columnsController = that._columnsController;
489-
const rowCount = that.getRowCount();
486+
const columnsController = this._columnsController;
487+
const rowCount = this.getRowCount();
490488

491-
if (that.option('showColumnHeaders')) {
489+
if (this.option('showColumnHeaders')) {
492490
if (rowCount > 1 && (!isDefined(index) || isDefined(bandColumnIndex))) {
493491
const result: any[] = [];
494-
const visibleColumns = isDefined(bandColumnIndex) ? columnsController.getChildrenByBandColumn(bandColumnIndex, true) : columnsController.getVisibleColumns();
495492

496-
each(visibleColumns, (_, column) => {
497-
const rowIndex = isDefined(index) ? index : columnsController.getRowIndex(column.index);
498-
$cellElement = that._getCellElement(rowIndex, columnsController.getVisibleIndex(column.index, rowIndex));
499-
$cellElement && result.push($cellElement.get(0));
493+
let visibleColumns: Column[] = [];
494+
if (isDefined(bandColumnIndex)) {
495+
visibleColumns = columnsController.getChildrenByBandColumn(bandColumnIndex, true);
496+
} else {
497+
visibleColumns = columnsController.getVisibleColumns();
498+
}
499+
500+
visibleColumns.forEach((column) => {
501+
const rowIndex = index ?? columnsController.getRowIndex(column.index);
502+
const visibleIndex = columnsController.getVisibleIndex(column.index, rowIndex);
503+
$cellElement = this._getCellElement(rowIndex, visibleIndex);
504+
if ($cellElement) {
505+
result.push($cellElement.get(0));
506+
}
500507
});
501508

502509
return $(result);
503510
} if (!index || index < rowCount) {
504-
return that.getCellElements(index || 0);
511+
return this.getCellElements(index || 0);
505512
}
506513
}
507514

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,9 +1836,18 @@ export class ColumnsController extends modules.Controller {
18361836

18371837
public getRowIndex(columnIndex, alwaysGetRowIndex?) {
18381838
const column = this._columns[columnIndex];
1839-
const bandColumnsCache = this.getBandColumnsCache();
1839+
if (!column) {
1840+
return 0;
1841+
}
18401842

1841-
return column && (alwaysGetRowIndex || column.visible && !(column.command || isDefined(column.groupIndex))) ? getParentBandColumns(columnIndex, bandColumnsCache.columnParentByIndex).length : 0;
1843+
const isCommandOrGroupColumn = column.command || this._isColumnInGroupPanel(column);
1844+
const isVisibleDataColumn = column.visible && !isCommandOrGroupColumn;
1845+
if (!alwaysGetRowIndex && !isVisibleDataColumn) {
1846+
return 0;
1847+
}
1848+
1849+
const bandColumnsCache = this.getBandColumnsCache();
1850+
return getParentBandColumns(columnIndex, bandColumnsCache.columnParentByIndex).length;
18421851
}
18431852

18441853
public getChildrenByBandColumn(bandColumnIndex, onlyVisibleDirectChildren?) {

0 commit comments

Comments
 (0)