Skip to content

Commit 31f7be4

Browse files
authored
DataGrid – Resize indicator is moved when resizing a grouped column if showWhenGrouped is set to true (T1314667) (#31913)
1 parent c9fb792 commit 31f7be4

File tree

3 files changed

+82
-13
lines changed

3 files changed

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

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ 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 type { HeaderFilterController } from '@ts/grids/grid_core/header_filter/m_header_filter';
1211
import type { HeaderPanel } from '@ts/grids/grid_core/header_panel/m_header_panel';
1312

13+
import type { Column } from '../columns_controller/m_columns_controller';
1414
import { CLASSES as REORDERING_CLASSES } from '../columns_resizing_reordering/const';
1515
import { registerKeyboardAction } from '../m_accessibility';
1616
import { ColumnsView } from '../views/m_columns_view';
@@ -458,26 +458,34 @@ export class ColumnHeadersView extends ColumnsView {
458458
}
459459

460460
public getColumnElements(index?, bandColumnIndex?) {
461-
const that = this;
462461
let $cellElement;
463-
const columnsController = that._columnsController;
464-
const rowCount = that.getRowCount();
462+
const columnsController = this._columnsController;
463+
const rowCount = this.getRowCount();
465464

466-
if (that.option('showColumnHeaders')) {
465+
if (this.option('showColumnHeaders')) {
467466
if (rowCount > 1 && (!isDefined(index) || isDefined(bandColumnIndex))) {
468467
const result: any[] = [];
469-
const visibleColumns = isDefined(bandColumnIndex) ? columnsController.getChildrenByBandColumn(bandColumnIndex, true) : columnsController.getVisibleColumns();
470468

471-
each(visibleColumns, (_, column) => {
472-
const rowIndex = isDefined(index) ? index : columnsController.getRowIndex(column.index);
473-
$cellElement = that._getCellElement(rowIndex, columnsController.getVisibleIndex(column.index, rowIndex));
474-
$cellElement && result.push($cellElement.get(0));
469+
let visibleColumns: Column[] = [];
470+
if (isDefined(bandColumnIndex)) {
471+
visibleColumns = columnsController.getChildrenByBandColumn(bandColumnIndex, true);
472+
} else {
473+
visibleColumns = columnsController.getVisibleColumns();
474+
}
475+
476+
visibleColumns.forEach((column) => {
477+
const rowIndex = index ?? columnsController.getRowIndex(column.index);
478+
const visibleIndex = columnsController.getVisibleIndex(column.index, rowIndex);
479+
$cellElement = this._getCellElement(rowIndex, visibleIndex);
480+
if ($cellElement) {
481+
result.push($cellElement.get(0));
482+
}
475483
});
476484

477485
// @ts-expect-error
478486
return $(result);
479487
} if (!index || index < rowCount) {
480-
return that.getCellElements(index || 0);
488+
return this.getCellElements(index || 0);
481489
}
482490
}
483491

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
@@ -1783,9 +1783,18 @@ export class ColumnsController extends modules.Controller {
17831783

17841784
public getRowIndex(columnIndex, alwaysGetRowIndex?) {
17851785
const column = this._columns[columnIndex];
1786-
const bandColumnsCache = this.getBandColumnsCache();
1786+
if (!column) {
1787+
return 0;
1788+
}
17871789

1788-
return column && (alwaysGetRowIndex || column.visible && !(column.command || isDefined(column.groupIndex))) ? getParentBandColumns(columnIndex, bandColumnsCache.columnParentByIndex).length : 0;
1790+
const isCommandOrGroupColumn = column.command || this._isColumnInGroupPanel(column);
1791+
const isVisibleDataColumn = column.visible && !isCommandOrGroupColumn;
1792+
if (!alwaysGetRowIndex && !isVisibleDataColumn) {
1793+
return 0;
1794+
}
1795+
1796+
const bandColumnsCache = this.getBandColumnsCache();
1797+
return getParentBandColumns(columnIndex, bandColumnsCache.columnParentByIndex).length;
17891798
}
17901799

17911800
public getChildrenByBandColumn(bandColumnIndex, onlyVisibleDirectChildren?) {

0 commit comments

Comments
 (0)