Skip to content

Commit 9b32fc4

Browse files
authored
DataGrid – Resize indicator is moved when resizing a grouped column if showWhenGrouped is set to true (T1314667) (#31912)
1 parent bcf2a8f commit 9b32fc4

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

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,13 +5,13 @@ 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';
1211
import type { HeaderFilterController } from '@ts/grids/grid_core/header_filter/m_header_filter';
1312
import type { HeaderPanel } from '@ts/grids/grid_core/header_panel/m_header_panel';
1413

14+
import type { Column } from '../columns_controller/m_columns_controller';
1515
import { CLASSES as REORDERING_CLASSES } from '../columns_resizing_reordering/const';
1616
import type { HeadersKeyboardNavigationController } from '../keyboard_navigation/m_headers_keyboard_navigation';
1717
import { registerKeyboardAction } from '../m_accessibility';
@@ -467,25 +467,33 @@ export class ColumnHeadersView extends ColumnContextMenuMixin(ColumnsView) {
467467
}
468468

469469
public getColumnElements(index?, bandColumnIndex?) {
470-
const that = this;
471470
let $cellElement;
472-
const columnsController = that._columnsController;
473-
const rowCount = that.getRowCount();
471+
const columnsController = this._columnsController;
472+
const rowCount = this.getRowCount();
474473

475-
if (that.option('showColumnHeaders')) {
474+
if (this.option('showColumnHeaders')) {
476475
if (rowCount > 1 && (!isDefined(index) || isDefined(bandColumnIndex))) {
477476
const result: any[] = [];
478-
const visibleColumns = isDefined(bandColumnIndex) ? columnsController.getChildrenByBandColumn(bandColumnIndex, true) : columnsController.getVisibleColumns();
479477

480-
each(visibleColumns, (_, column) => {
481-
const rowIndex = isDefined(index) ? index : columnsController.getRowIndex(column.index);
482-
$cellElement = that._getCellElement(rowIndex, columnsController.getVisibleIndex(column.index, rowIndex));
483-
$cellElement && result.push($cellElement.get(0));
478+
let visibleColumns: Column[] = [];
479+
if (isDefined(bandColumnIndex)) {
480+
visibleColumns = columnsController.getChildrenByBandColumn(bandColumnIndex, true);
481+
} else {
482+
visibleColumns = columnsController.getVisibleColumns();
483+
}
484+
485+
visibleColumns.forEach((column) => {
486+
const rowIndex = index ?? columnsController.getRowIndex(column.index);
487+
const visibleIndex = columnsController.getVisibleIndex(column.index, rowIndex);
488+
$cellElement = this._getCellElement(rowIndex, visibleIndex);
489+
if ($cellElement) {
490+
result.push($cellElement.get(0));
491+
}
484492
});
485493

486494
return $(result);
487495
} if (!index || index < rowCount) {
488-
return that.getCellElements(index || 0);
496+
return this.getCellElements(index || 0);
489497
}
490498
}
491499

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

17911791
public getRowIndex(columnIndex, alwaysGetRowIndex?) {
17921792
const column = this._columns[columnIndex];
1793-
const bandColumnsCache = this.getBandColumnsCache();
1793+
if (!column) {
1794+
return 0;
1795+
}
17941796

1795-
return column && (alwaysGetRowIndex || column.visible && !(column.command || isDefined(column.groupIndex))) ? getParentBandColumns(columnIndex, bandColumnsCache.columnParentByIndex).length : 0;
1797+
const isCommandOrGroupColumn = column.command || this._isColumnInGroupPanel(column);
1798+
const isVisibleDataColumn = column.visible && !isCommandOrGroupColumn;
1799+
if (!alwaysGetRowIndex && !isVisibleDataColumn) {
1800+
return 0;
1801+
}
1802+
1803+
const bandColumnsCache = this.getBandColumnsCache();
1804+
return getParentBandColumns(columnIndex, bandColumnsCache.columnParentByIndex).length;
17961805
}
17971806

17981807
public getChildrenByBandColumn(bandColumnIndex, onlyVisibleDirectChildren?) {

0 commit comments

Comments
 (0)