Skip to content

Commit 02376cc

Browse files
authored
DataGrid: Fix broken layout after resizing window when there are fixed and band columns (T1193153) (#25880)
Co-authored-by: Alyar <>
1 parent 00c35b8 commit 02376cc

5 files changed

Lines changed: 83 additions & 9 deletions

File tree

packages/devextreme/js/__internal/grids/grid_core/views/m_columns_view.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,19 +1119,20 @@ export class ColumnsView extends viewWithColumnStateMixin {
11191119
const $rows = $tableElement.children().children('.dx-row').not(`.${DETAIL_ROW_CLASS}`);
11201120

11211121
for (let rowIndex = 0; rowIndex < $rows.length; rowIndex++) {
1122-
const $row = $rows.eq(rowIndex);
1123-
11241122
const visibleIndex = this.getVisibleColumnIndex(columnIndex, rowIndex);
11251123

1126-
const $cell = $row.hasClass(GROUP_ROW_CLASS)
1127-
? $row.find(`td[aria-colindex='${visibleIndex + 1}']:not(.${GROUP_CELL_CLASS})`)
1128-
: $row.find('td').eq(visibleIndex);
1124+
if (visibleIndex >= 0) {
1125+
const $row = $rows.eq(rowIndex);
1126+
const $cell = $row.hasClass(GROUP_ROW_CLASS)
1127+
? $row.find(`td[aria-colindex='${visibleIndex + 1}']:not(.${GROUP_CELL_CLASS})`)
1128+
: $row.find('td').eq(visibleIndex);
11291129

1130-
const cell = $cell.get(0) as HTMLElement;
1130+
if ($cell.length) {
1131+
const cell = $cell.get(0) as HTMLElement;
11311132

1132-
if (cell) {
1133-
setCellWidth(cell, column, width);
1134-
cell.style.minWidth = minWidth;
1133+
setCellWidth(cell, column, width);
1134+
cell.style.minWidth = minWidth;
1135+
}
11351136
}
11361137
}
11371138
}
5.28 KB
Loading
4.95 KB
Loading

packages/devextreme/testing/testcafe/tests/dataGrid/fixedColumns.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,41 @@ test.skip('Hovering over a row should work correctly after scrolling when there
322322

323323
await makeRowsViewTemplatesAsync(DATA_GRID_SELECTOR, 100);
324324
});
325+
326+
// T1193153
327+
safeSizeTest('The grid layout should be correct after resizing the window when there are fixed and band columns', async (t) => {
328+
// arrange
329+
const dataGrid = new DataGrid('#container');
330+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
331+
332+
// assert
333+
await t
334+
.expect(dataGrid.isReady())
335+
.ok();
336+
337+
// act
338+
await takeScreenshot('T1193153-layout-with-fixed-and-band-columns-1.png', dataGrid.element);
339+
await t.resizeWindow(400, 400);
340+
await takeScreenshot('T1193153-layout-with-fixed-and-band-columns-2.png', dataGrid.element);
341+
342+
// assert
343+
await t
344+
.expect(compareResults.isValid())
345+
.ok(compareResults.errorMessages());
346+
}, [800, 800]).before(async () => createWidget('dxDataGrid', {
347+
columnAutoWidth: true,
348+
dataSource: [{}],
349+
columns: [{
350+
caption: 'Fixed column',
351+
fixed: true,
352+
columns: [{
353+
caption: 'Banded column',
354+
width: 150,
355+
}],
356+
}, {
357+
caption: 'Default column',
358+
}, {
359+
type: 'buttons',
360+
width: 50,
361+
}],
362+
}));

packages/devextreme/testing/tests/DevExpress.ui.widgets.dataGrid/columnsHeadersView.tests.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,41 @@ QUnit.module('Headers with band columns', {
28032803
assert.strictEqual($(headerCellElement).attr('rowspan'), undefined);
28042804
});
28052805
});
2806+
2807+
// T1193153
2808+
QUnit.test('setColumnWidths - the command column should have the correct minWidth, width, maxWidth when there are band columns', function(assert) {
2809+
// arrange
2810+
const $testElement = $('#container');
2811+
2812+
this.columns = [{
2813+
caption: 'Band column 1',
2814+
columns: [{
2815+
caption: 'column 1',
2816+
width: 150
2817+
}]
2818+
}, {
2819+
caption: 'Default column'
2820+
}, {
2821+
type: 'buttons',
2822+
width: 50,
2823+
command: 'edit',
2824+
visible: true,
2825+
cssClass: 'dx-command-edit',
2826+
}];
2827+
this.options.columnAutoWidth = true;
2828+
this.setupDataGrid();
2829+
this.columnHeadersView.render($testElement);
2830+
2831+
// act
2832+
this.columnHeadersView.setColumnWidths({ widths: [150, 666, 50] });
2833+
2834+
// assert
2835+
const commandCell = $testElement.find('td').get(2);
2836+
assert.ok($(commandCell).hasClass('dx-command-edit'), 'command column');
2837+
assert.strictEqual(commandCell.style.width, '50px', 'width of the command column');
2838+
assert.strictEqual(commandCell.style.minWidth, '50px', 'minWidth of the command column');
2839+
assert.strictEqual(commandCell.style.maxWidth, '50px', 'maxWidth of the command column');
2840+
});
28062841
});
28072842

28082843
QUnit.module('Multiple sorting', {

0 commit comments

Comments
 (0)