Skip to content

Commit b90baf3

Browse files
AmbrozyCORP\vladimir.bushmanov
and
CORP\vladimir.bushmanov
authored
T1264497: DataGrid - fix separator height for grouped columns (#28827)
Co-authored-by: CORP\vladimir.bushmanov <vladimir.bushmanov@devexpress.com>
1 parent 6fa6bef commit b90baf3

File tree

14 files changed

+130
-17
lines changed

14 files changed

+130
-17
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
2+
import DataGrid from 'devextreme-testcafe-models/dataGrid';
3+
4+
import url from '../../helpers/getPageUrl';
5+
import { createWidget } from '../../helpers/createWidget';
6+
7+
fixture`Column resizing`
8+
.page(url(__dirname, '../container.html'));
9+
10+
test('column separator should starts from the parent', async (t) => {
11+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
12+
const dataGrid = new DataGrid('#container');
13+
async function makeColumnSeparatorScreenshot(index: number) {
14+
await dataGrid.resizeHeader(index, 0, false);
15+
await t.expect(await takeScreenshot(`column-separator-${index}.png`)).ok();
16+
await t.dispatchEvent(dataGrid.element, 'mouseup');
17+
}
18+
19+
await makeColumnSeparatorScreenshot(1);
20+
await makeColumnSeparatorScreenshot(2);
21+
await makeColumnSeparatorScreenshot(3);
22+
await makeColumnSeparatorScreenshot(4);
23+
await makeColumnSeparatorScreenshot(5);
24+
await makeColumnSeparatorScreenshot(6);
25+
await makeColumnSeparatorScreenshot(7);
26+
await makeColumnSeparatorScreenshot(8);
27+
await makeColumnSeparatorScreenshot(9);
28+
29+
await t
30+
.expect(compareResults.isValid())
31+
.ok(compareResults.errorMessages());
32+
}).before(async () => createWidget('dxDataGrid', {
33+
dataSource: [{
34+
ID: 1,
35+
Country: 'Brazil',
36+
Area: 8515767,
37+
Population_Urban: 0.85,
38+
Population_Rural: 0.15,
39+
Population_Total: 205809000,
40+
GDP_Agriculture: 0.054,
41+
GDP_Industry: 0.274,
42+
GDP_Services: 0.672,
43+
GDP_Total: 2353025,
44+
}],
45+
keyExpr: 'ID',
46+
columnWidth: 100,
47+
allowColumnResizing: true,
48+
showBorders: true,
49+
editing: {
50+
allowUpdating: true,
51+
},
52+
columns: ['Country', {
53+
dataField: 'Population_Total',
54+
visible: false,
55+
}, {
56+
caption: 'Population',
57+
columns: ['Population_Rural', {
58+
caption: 'By Sector',
59+
columns: ['GDP_Total', {
60+
caption: 'not resizable',
61+
dataField: 'ID',
62+
allowResizing: false,
63+
}, 'GDP_Agriculture', 'GDP_Industry'],
64+
}],
65+
}, {
66+
caption: 'Nominal GDP',
67+
columns: ['GDP_Total', 'Population_Urban'],
68+
}, 'Area'],
69+
}));
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

packages/devextreme/js/__internal/grids/grid_core/columns_resizing_reordering/m_columns_resizing_reordering.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import { isDefined, isObject, isString } from '@js/core/utils/type';
2323
import swatchContainer from '@js/ui/widget/swatch_container';
2424
import type { EditorFactory } from '@ts/grids/grid_core/editor_factory/m_editor_factory';
25-
import type { ModuleType } from '@ts/grids/grid_core/m_types';
25+
import type { ColumnPoint, ModuleType } from '@ts/grids/grid_core/m_types';
2626
import type { RowsView } from '@ts/grids/grid_core/views/m_rows_view';
2727

2828
import type { ColumnChooserView } from '../column_chooser/m_column_chooser';
@@ -914,27 +914,60 @@ export class ColumnsResizerViewController extends modules.ViewController {
914914
}
915915
}
916916

917+
private _generateColumnsTopYIndex(needToCheckPrevPoint = false) {
918+
const that = this;
919+
const rowCount = that._columnsController.getRowCount();
920+
const topYMap: Record<number, number> = {};
921+
const pointCreated = (point: ColumnPoint): boolean => {
922+
const x = Math.ceil(point.x);
923+
924+
if (!topYMap[x]) {
925+
topYMap[x] = point.y;
926+
}
927+
928+
return true;
929+
};
930+
931+
for (let rowIndex = 0; rowIndex < rowCount - 1; rowIndex++) {
932+
const cells = that._columnHeadersView.getColumnElements(rowIndex);
933+
934+
if (cells && cells.length > 0) {
935+
gridCoreUtils.getPointsByColumns(cells, pointCreated, false, 0, needToCheckPrevPoint);
936+
}
937+
}
938+
939+
return topYMap;
940+
}
941+
917942
/**
918943
* @extended: column_fixing
919944
* @protected
920945
*/
921946
protected _generatePointsByColumns(needToCheckPrevPoint = false) {
922947
const that = this;
948+
const topYMap = that._generateColumnsTopYIndex(needToCheckPrevPoint);
923949
const columns = that._columnsController ? that._columnsController.getVisibleColumns() : [];
924950
const cells = that._columnHeadersView.getColumnElements();
925-
let pointsByColumns: any = [];
951+
const correctColumnY = (point: ColumnPoint): ColumnPoint => {
952+
const x = Math.ceil(point.x);
953+
954+
if (topYMap[x]) {
955+
point.y = topYMap[x];
956+
}
957+
958+
return point;
959+
};
926960

961+
that._pointsByColumns = [];
927962
if (cells && cells.length > 0) {
928-
pointsByColumns = gridCoreUtils.getPointsByColumns(
963+
that._pointsByColumns = gridCoreUtils.getPointsByColumns(
929964
cells,
930-
(point) => that._pointCreated(point, cells.length, columns),
965+
(point) => that._pointCreated(correctColumnY(point), cells.length, columns),
931966
false,
932967
0,
933968
needToCheckPrevPoint,
934969
);
935970
}
936-
937-
that._pointsByColumns = pointsByColumns;
938971
}
939972

940973
// eslint-disable-next-line @typescript-eslint/no-unused-vars

packages/devextreme/js/__internal/grids/grid_core/m_types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export type GridPropertyType<T, TProp extends string> = PropertyType<T, TProp> e
1616
// Data types
1717
export type RowKey = unknown;
1818

19+
export interface ColumnPoint {
20+
index: number;
21+
columnIndex: number;
22+
x: number;
23+
y: number;
24+
}
25+
1926
// todo: move to upper .d.ts
2027
type OptionsMethod<TOptions> =
2128
(() => TOptions) &

packages/devextreme/js/__internal/grids/grid_core/m_utils.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { getWindow } from '@js/core/utils/window';
1919
import formatHelper from '@js/format_helper';
2020
import LoadPanel from '@js/ui/load_panel';
2121
import sharedFiltering from '@js/ui/shared/filtering';
22+
import type { ColumnPoint } from '@ts/grids/grid_core/m_types';
2223

2324
const DATAGRID_SELECTION_DISABLED_CLASS = 'dx-selection-disabled';
2425
const DATAGRID_GROUP_OPENED_CLASS = 'dx-datagrid-group-opened';
@@ -154,16 +155,14 @@ const equalFilterParameters = function (filter1, filter2) {
154155
return toComparable(filter1) == toComparable(filter2); // eslint-disable-line eqeqeq
155156
};
156157

157-
const createPoint = function (options): Record<string, any> {
158-
return {
159-
index: options.index,
160-
columnIndex: options.columnIndex,
161-
x: options.x,
162-
y: options.y,
163-
};
164-
};
158+
const createPoint = <T extends ColumnPoint>(options: T): ColumnPoint => ({
159+
index: options.index,
160+
columnIndex: options.columnIndex,
161+
x: options.x,
162+
y: options.y,
163+
});
165164

166-
const addPointIfNeed = function (points, pointProps, pointCreated): void {
165+
const addPointIfNeed = <T extends ColumnPoint> (points: ColumnPoint[], pointProps: T, pointCreated: (point: T) => boolean): void => {
167166
let notCreatePoint = false;
168167

169168
if (pointCreated) {
@@ -439,8 +438,8 @@ export default {
439438
return (!sortParameters1 || !sortParameters1.length) === (!sortParameters2 || !sortParameters2.length);
440439
},
441440

442-
getPointsByColumns(items, pointCreated, isVertical?, startColumnIndex = 0, needToCheckPrevPoint = false) {
443-
const result: any[] = [];
441+
getPointsByColumns<T extends ColumnPoint>(items, pointCreated: (point: T) => boolean, isVertical = false, startColumnIndex = 0, needToCheckPrevPoint = false): ColumnPoint[] {
442+
const result: ColumnPoint[] = [];
444443
const cellsLength: number = items.length;
445444
let $item;
446445
let offset: { left: number; top: number } = { left: 0, top: 0 };

packages/testcafe-models/dataGrid/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const CLASS = {
6868
dialogWrapper: 'dx-dialog-wrapper',
6969
summaryTotal: 'dx-datagrid-summary-item',
7070
scrollableContainer: 'dx-scrollable-container',
71+
columnsSeparator: 'dx-datagrid-columns-separator',
7172
};
7273

7374
const E2E_ATTRIBUTES = {
@@ -239,6 +240,10 @@ export default class DataGrid extends Widget {
239240
return new TextBox(this.element.find(`.${CLASS.searchBox}`));
240241
}
241242

243+
getColumnsSeparator(): TextBox {
244+
return new TextBox(this.element.find(`.${CLASS.columnsSeparator}`));
245+
}
246+
242247
getOverlay(): Overlay {
243248
return new Overlay(this.element.find(`.${CLASS.overlayWrapper}`));
244249
}

0 commit comments

Comments
 (0)