From 692753de38bb9a2f428932afc6b7bb9269dd4cb6 Mon Sep 17 00:00:00 2001 From: Aliar666 Date: Fri, 4 Dec 2026 20:46:44 +0400 Subject: [PATCH 1/6] Grids: ColumnsController - cover column merging and fixing through the public API --- ...columns_controller.visible_columns.test.ts | 332 ++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts new file mode 100644 index 000000000000..9e1eeb1a2889 --- /dev/null +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts @@ -0,0 +1,332 @@ +import { + afterEach, beforeEach, describe, expect, it, +} from '@jest/globals'; +import type { Response as SendRequestResult } from '@js/common/ai-integration'; +import type { Properties as DataGridProperties } from '@js/ui/data_grid'; +import { AIIntegration } from '@ts/core/ai_integration/core/ai_integration'; +import type { ColumnsController } from '@ts/grids/grid_core/columns_controller/columns_controller'; +import type { Column } from '@ts/grids/grid_core/columns_controller/types'; + +import { + afterTest, + beforeTest, + createDataGrid, +} from '../../__tests__/__mock__/helpers/utils'; + +type ColumnOptions = NonNullable[number]; + +const SELECTION: DataGridProperties = { selection: { mode: 'multiple', showCheckBoxesMode: 'always' } }; +const EDITING: DataGridProperties = { editing: { allowUpdating: true } }; + +const AI_COLUMN: ColumnOptions = { + type: 'ai', + name: 'ai', + caption: 'AI', + ai: { + aiIntegration: new AIIntegration({ + sendRequest: (): SendRequestResult => ({ promise: Promise.resolve('{}'), abort: (): void => {} }), + }), + }, +}; + +const getColumnsController = async (options: DataGridProperties): Promise => { + const { instance } = await createDataGrid({ dataSource: [], ...options }); + + return instance.getController('columns'); +}; + +const findByCommand = (columns: Column[], command: string): Column | undefined => columns + .find((column) => column.command === command); + +const getNames = (columns: Column[]): (string | undefined)[] => columns + .map(({ dataField, command }) => dataField ?? command); + +describe('getVisibleColumns', () => { + beforeEach(beforeTest); + afterEach(afterTest); + + describe('with command columns', () => { + it('should return copies of the grid columns', async () => { + const columnsController = await getColumnsController({ columns: ['a', 'b'] }); + const columns = columnsController.getColumns(); + + const visibleColumns = columnsController.getVisibleColumns(); + + expect(visibleColumns).toEqual(columns); + expect(visibleColumns[0]).not.toBe(columns[0]); + expect(visibleColumns[1]).not.toBe(columns[1]); + }); + + it('should add a command column', async () => { + const columnsController = await getColumnsController({ columns: ['a'], ...SELECTION }); + + const visibleColumns = columnsController.getVisibleColumns(); + + expect(getNames(visibleColumns)).toEqual(['select', 'a']); + expect(findByCommand(visibleColumns, 'select')?.fixed).toBe(false); + }); + + it('should not add command columns when the grid has no columns', async () => { + const columnsController = await getColumnsController({ columns: [], ...SELECTION }); + + expect(columnsController.getVisibleColumns()).toEqual([]); + }); + + it.each<[string, DataGridProperties]>([ + ['column fixing is enabled', { columns: ['a'], columnFixing: { enabled: true } }], + ['a column is fixed', { columns: [{ dataField: 'a', fixed: true }] }], + ])('should fix a command column when %s', async (_, options) => { + const columnsController = await getColumnsController({ ...options, ...SELECTION }); + + expect(findByCommand(columnsController.getVisibleColumns(), 'select')?.fixed).toBe(true); + }); + + it('should keep the fixed option of a command column', async () => { + const columnsController = await getColumnsController({ + columns: ['a', AI_COLUMN], + columnFixing: { enabled: true }, + }); + + expect(findByCommand(columnsController.getVisibleColumns(), 'ai')?.fixed).toBe(false); + }); + + it('should merge a column into the command column of its type', async () => { + const columnsController = await getColumnsController({ + columns: ['a', { type: 'buttons', caption: 'Actions' }], + ...EDITING, + }); + + const [, column] = columnsController.getVisibleColumns(); + + expect(column).toMatchObject({ + type: 'buttons', command: 'edit', caption: 'Actions', width: 'auto', fixed: false, + }); + }); + + it('should not change the grid column it merges', async () => { + const columnsController = await getColumnsController({ + columns: ['a', { type: 'buttons', cssClass: 'custom' }], + ...EDITING, + }); + + columnsController.getVisibleColumns(); + + const [, column] = columnsController.getColumns(); + expect(column.command).toBeUndefined(); + expect(column.cssClass).toBe('custom'); + }); + + it('should let the column options override the command column options', async () => { + const columnsController = await getColumnsController({ + columns: ['a', { type: 'buttons', width: 100, fixed: true }], + ...EDITING, + }); + + const column = findByCommand(columnsController.getVisibleColumns(), 'edit'); + + expect(column?.width).toBe(100); + expect(column?.fixed).toBe(true); + }); + + it('should keep calculateCellValue of the command column', async () => { + const columnsController = await getColumnsController({ columns: ['a', AI_COLUMN] }); + const commandColumn = columnsController.columnOption('command:ai'); + + const column = findByCommand(columnsController.getVisibleColumns(), 'ai'); + + const [, gridColumn] = columnsController.getColumns(); + expect(column?.calculateCellValue).toBe(commandColumn?.calculateCellValue); + expect(column?.calculateCellValue).not.toBe(gridColumn.calculateCellValue); + }); + + it('should keep calculateCellValue of the column when the command column has none', async () => { + const columnsController = await getColumnsController({ + columns: ['a', { type: 'buttons' }], + ...EDITING, + }); + + const column = findByCommand(columnsController.getVisibleColumns(), 'edit'); + + expect(column?.calculateCellValue).toBe(columnsController.getColumns()[1].calculateCellValue); + }); + + it.each([ + ['both columns have one', 'custom', 'dx-command-edit custom'], + ['only the command column has one', undefined, 'dx-command-edit'], + ])('should join the css classes when %s', async (_, cssClass, expected) => { + const columnsController = await getColumnsController({ + columns: ['a', { type: 'buttons', cssClass }], + ...EDITING, + }); + + expect(findByCommand(columnsController.getVisibleColumns(), 'edit')?.cssClass).toBe(expected); + }); + + it('should add only the command columns that no column customizes', async () => { + const columnsController = await getColumnsController({ + columns: ['a', { type: 'buttons', caption: 'Actions' }], + ...EDITING, + ...SELECTION, + }); + + expect(getNames(columnsController.getVisibleColumns())).toEqual(['select', 'a', 'edit']); + }); + }); + + describe('with grouping', () => { + const DATA_SOURCE = [{ a: 1, b: 2, c: 3 }]; + const GROUPED_COLUMNS: ColumnOptions[] = ['a', { dataField: 'b', groupIndex: 0 }, { dataField: 'c', groupIndex: 1 }]; + + it('should apply the options of a groupExpand column to every group column', async () => { + const columnsController = await getColumnsController({ + dataSource: DATA_SOURCE, + columns: [...GROUPED_COLUMNS, { + type: 'groupExpand', caption: 'Group', cssClass: 'custom', width: 50, + }], + }); + const options = { + type: 'groupExpand', command: 'expand', caption: 'Group', cssClass: 'custom', width: 50, + }; + + const [, firstGroupColumn, secondGroupColumn] = columnsController.getVisibleColumns(); + + expect(firstGroupColumn).toMatchObject(options); + expect(secondGroupColumn).toMatchObject(options); + }); + + it('should keep the position of each group column', async () => { + const columnsController = await getColumnsController({ + dataSource: DATA_SOURCE, + columns: [...GROUPED_COLUMNS, { type: 'groupExpand', width: 50 }], + }); + const [, b, c] = columnsController.getColumns(); + + const [, firstGroupColumn, secondGroupColumn] = columnsController.getVisibleColumns(); + + expect(firstGroupColumn).toMatchObject({ + dataField: 'b', index: b.index, visibleIndex: b.visibleIndex, headerId: b.headerId, groupIndex: 0, + }); + expect(secondGroupColumn).toMatchObject({ + dataField: 'c', index: c.index, visibleIndex: c.visibleIndex, headerId: c.headerId, groupIndex: 1, + }); + }); + + it('should allow fixing and reordering only for the first group column', async () => { + const columnsController = await getColumnsController({ + dataSource: DATA_SOURCE, + columns: [...GROUPED_COLUMNS, { type: 'groupExpand' }], + }); + + const [, firstGroupColumn, secondGroupColumn] = columnsController.getVisibleColumns(); + + expect(firstGroupColumn).toMatchObject({ allowFixing: true, allowReordering: true }); + expect(secondGroupColumn).toMatchObject({ allowFixing: false, allowReordering: false }); + }); + + it('should put the group columns customized by a groupExpand column with the fixed columns', async () => { + const columnsController = await getColumnsController({ + dataSource: DATA_SOURCE, + columns: ['a', { dataField: 'b', groupIndex: 0 }, { type: 'groupExpand', caption: 'Group' }], + columnFixing: { enabled: true }, + }); + + const visibleColumns = columnsController.getVisibleColumns(); + + expect(visibleColumns.map(({ type, dataField }) => type ?? dataField)).toEqual(['groupExpand', 'a']); + expect(visibleColumns[0].fixed).toBe(true); + }); + + it('should not add the grid columns to the group columns', async () => { + const columnsController = await getColumnsController({ + dataSource: DATA_SOURCE, + columns: ['a', { dataField: 'b', groupIndex: 0 }], + }); + + const visibleColumns = columnsController.getVisibleColumns(); + + expect(visibleColumns.map(({ type, dataField }) => type ?? dataField)).toEqual(['groupExpand', 'a']); + }); + }); + + it('should let a detailExpand column override every option of the detail expand column', async () => { + const columnsController = await getColumnsController({ + dataSource: [{ a: 1 }], + columns: ['a', { type: 'detailExpand', width: 40 }], + masterDetail: { enabled: true }, + }); + const [, column] = columnsController.getColumns(); + + const detailExpandColumn = columnsController.getVisibleColumns() + .find(({ type }) => type === 'detailExpand'); + + expect(detailExpandColumn).toMatchObject({ + command: 'expand', width: 40, index: column.index, visibleIndex: column.visibleIndex, + }); + }); +}); + +describe('moveColumn', () => { + beforeEach(beforeTest); + afterEach(afterTest); + + const moveColumn = async ( + options: DataGridProperties, + fromVisibleIndex: number, + toVisibleIndex: number, + ): Promise => { + const columnsController = await getColumnsController(options); + + columnsController.moveColumn(fromVisibleIndex, toVisibleIndex, 'headers', 'headers'); + + return columnsController.getColumns().map(({ visibleIndex }) => visibleIndex as number); + }; + + it('should move a column to the place of a target column with the same fixing', async () => { + const [, b, c] = await moveColumn({ columns: [{ dataField: 'a', fixed: true }, 'b', 'c'] }, 2, 1); + + expect(c).toBeLessThan(b); + }); + + it('should move a column to the end when the target column is fixed and the column is not', async () => { + const [a, b, c] = await moveColumn({ columns: [{ dataField: 'a', fixed: true }, 'b', 'c'] }, 2, 0); + + expect(c).toBeGreaterThan(a); + expect(c).toBeGreaterThan(b); + }); + + it('should not treat a sticky column as fixed', async () => { + const [a, , c] = await moveColumn({ + columns: [{ dataField: 'a', fixed: true, fixedPosition: 'sticky' }, 'b', 'c'], + }, 2, 0); + + expect(c).toBeLessThan(a); + }); + + it.each<[string, ColumnOptions]>([ + ['a data column', 'c'], + ['an AI column', AI_COLUMN], + ])('should ignore the column fixing of the grid for %s', async (_, target) => { + const [a, , c] = await moveColumn({ columns: ['a', 'b', target], columnFixing: { enabled: true } }, 0, 2); + + expect(a).toBeLessThan(c); + }); + + it('should treat a command column as fixed when the column fixing of the grid is enabled', async () => { + const [a, , buttons] = await moveColumn({ + columns: ['a', 'b', { type: 'buttons' }], + columnFixing: { enabled: true }, + ...EDITING, + }, 0, 2); + + expect(a).toBeGreaterThan(buttons); + }); + + it('should treat a command column as not fixed when the column fixing of the grid is disabled', async () => { + const [a, , buttons] = await moveColumn({ + columns: ['a', 'b', { type: 'buttons' }], + ...EDITING, + }, 0, 2); + + expect(a).toBeLessThan(buttons); + }); +}); From 2e6d9654961d03cc0b369a5e9c1cdcdddd4763cd Mon Sep 17 00:00:00 2001 From: Aliar666 Date: Fri, 4 Dec 2026 20:49:01 +0400 Subject: [PATCH 2/6] Grids: ColumnsController - move mergeColumns into the class --- .../columns_controller_utils.test.ts | 323 +----------------- .../columns_controller/columns_controller.ts | 72 +++- .../columns_controller_utils.ts | 67 ---- 3 files changed, 72 insertions(+), 390 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts index 8dd188150f4d..7d3e21c5138b 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts @@ -26,7 +26,6 @@ import { getSerializationFormat, getValueDataType, isColumnFixed, - mergeColumns, numberToString, processBandColumns, reserveGroupIndex, @@ -1213,319 +1212,6 @@ describe('getCommandColumnIndex', () => { }); }); -describe('mergeColumns', () => { - beforeEach(beforeTest); - afterEach(afterTest); - - describe('when merging the command columns into the columns', () => { - const selectColumn: Column = { type: 'selection', command: 'select' }; - const editColumn: Column = { type: 'buttons', command: 'edit', width: 'auto' }; - - it('should return copies of the columns', async () => { - const columnsController = await getColumnsController(); - const columns: Column[] = [{ dataField: 'a' }, { dataField: 'b' }]; - - const result = mergeColumns(columnsController, columns, [], true); - - expect(result).toEqual(columns); - expect(result[0]).not.toBe(columns[0]); - expect(result[1]).not.toBe(columns[1]); - }); - - it('should append the command columns after the columns', async () => { - const columnsController = await getColumnsController(); - - const result = mergeColumns(columnsController, [{ dataField: 'a' }], [selectColumn], true); - - expect(result).toEqual([ - { dataField: 'a' }, - { type: 'selection', command: 'select', fixed: false }, - ]); - }); - - it('should not append the command columns when there are no columns', async () => { - const columnsController = await getColumnsController(); - - expect(mergeColumns(columnsController, [], [selectColumn], true)).toEqual([]); - }); - - it.each<[string, DataGridProperties & ColumnsControllerOptions]>([ - ['column fixing is enabled', { columnFixing: { enabled: true } }], - ['a column is fixed', { columns: [{ dataField: 'a', fixed: true }] }], - ])('should fix the appended command columns when %s', async (_, options) => { - const columnsController = await getColumnsController(options); - - const [, commandColumn] = mergeColumns(columnsController, [{ dataField: 'a' }], [selectColumn], true); - - expect(commandColumn.fixed).toBe(true); - }); - - it('should keep the fixed option of a command column', async () => { - const columnsController = await getColumnsController({ columnFixing: { enabled: true } }); - const aiColumn: Column = { type: 'ai', command: 'ai', fixed: false }; - - const [, commandColumn] = mergeColumns(columnsController, [{ dataField: 'a' }], [aiColumn], true); - - expect(commandColumn.fixed).toBe(false); - }); - - it('should not change the passed columns', async () => { - const columnsController = await getColumnsController(); - const columns: Column[] = [{ dataField: 'a' }, { type: 'buttons', cssClass: 'custom' }]; - const commandColumns: Column[] = [selectColumn, { ...editColumn, cssClass: 'edit' }]; - const columnsCopy = columns.map((column) => ({ ...column })); - const commandColumnsCopy = commandColumns.map((column) => ({ ...column })); - - mergeColumns(columnsController, columns, commandColumns, true); - - expect(columns).toEqual(columnsCopy); - expect(commandColumns).toEqual(commandColumnsCopy); - }); - - it.each<[string, Column]>([ - ['type', { type: 'buttons' }], - ['command', { command: 'edit' }], - ])('should merge a column into the command column with the same %s', async (_, column) => { - const columnsController = await getColumnsController(); - - const result = mergeColumns( - columnsController, - [{ dataField: 'a' }, { ...column, caption: 'Actions' }], - [editColumn], - true, - ); - - expect(result).toEqual([ - { dataField: 'a' }, - { - type: 'buttons', command: 'edit', width: 'auto', caption: 'Actions', cssClass: '', fixed: false, - }, - ]); - }); - - it('should let the column options override the command column options', async () => { - const columnsController = await getColumnsController(); - - const [column] = mergeColumns( - columnsController, - [{ type: 'buttons', width: 100, fixed: true }], - [editColumn], - true, - ); - - expect(column.width).toBe(100); - expect(column.fixed).toBe(true); - }); - - it('should keep calculateCellValue of the command column', async () => { - const columnsController = await getColumnsController(); - const calculateCellValue = (): string => 'command'; - - const [column] = mergeColumns( - columnsController, - [{ type: 'ai', calculateCellValue: (): string => 'column' }], - [{ type: 'ai', command: 'ai', calculateCellValue }], - true, - ); - - expect(column.calculateCellValue).toBe(calculateCellValue); - }); - - it('should keep calculateCellValue of the column when the command column has none', async () => { - const columnsController = await getColumnsController(); - const calculateCellValue = (): string => 'column'; - - const [column] = mergeColumns( - columnsController, - [{ type: 'buttons', calculateCellValue }], - [editColumn], - true, - ); - - expect(column.calculateCellValue).toBe(calculateCellValue); - }); - - it.each([ - ['both columns', 'edit', 'custom', 'edit custom'], - ['only the command column', 'edit', undefined, 'edit'], - ['only the column', undefined, 'custom', 'custom'], - ['neither column', undefined, undefined, ''], - ])('should join the css classes when %s have one', async (_, commandCssClass, cssClass, expected) => { - const columnsController = await getColumnsController(); - - const [column] = mergeColumns( - columnsController, - [{ type: 'buttons', cssClass }], - [{ ...editColumn, cssClass: commandCssClass }], - true, - ); - - expect(column.cssClass).toBe(expected); - }); - - it('should append only the command columns that no column customizes', async () => { - const columnsController = await getColumnsController(); - - const result = mergeColumns( - columnsController, - [{ dataField: 'a' }, { type: 'buttons' }], - [selectColumn, editColumn], - true, - ); - - expect(result.map(({ dataField, command }) => dataField ?? command)).toEqual(['a', 'edit', 'select']); - }); - - it('should use the last command column that matches', async () => { - const columnsController = await getColumnsController(); - - const result = mergeColumns( - columnsController, - [{ type: 'buttons', command: 'select' }], - [{ ...editColumn, caption: 'Edit' }, { ...selectColumn, caption: 'Select' }], - true, - ); - - expect(result.map(({ caption }) => caption)).toEqual(['Select', 'Edit']); - }); - - it('should not merge a column without a type and a command into a command column', async () => { - const columnsController = await getColumnsController(); - - const result = mergeColumns(columnsController, [{ dataField: 'a' }], [{ command: 'custom' }], true); - - expect(result).toEqual([ - { dataField: 'a' }, - { command: 'custom', fixed: false }, - ]); - }); - - describe('when a column customizes the group expand column', () => { - const expandColumn: Column = { type: 'expand', command: 'expand', cssClass: 'expand' }; - - it('should merge it into the expand command column', async () => { - const columnsController = await getColumnsController(); - - const [column] = mergeColumns( - columnsController, - [{ type: 'groupExpand', caption: 'Group' }], - [expandColumn], - true, - ); - - expect(column).toEqual({ - type: 'groupExpand', command: 'expand', caption: 'Group', cssClass: 'expand', fixed: false, - }); - }); - - it('should still append the expand command column', async () => { - const columnsController = await getColumnsController(); - - const result = mergeColumns(columnsController, [{ type: 'groupExpand' }], [expandColumn], true); - - expect(result).toHaveLength(2); - expect(result[1]).toEqual({ ...expandColumn, fixed: false }); - }); - }); - }); - - describe('when merging the columns into the expand columns', () => { - const groupExpandColumn: Column = { - type: 'groupExpand', - command: 'expand', - index: 1, - visibleIndex: 2, - headerId: 'dx-col-1', - groupIndex: 0, - cssClass: 'expand', - width: 'auto', - }; - - it('should return copies of the expand columns and append nothing', async () => { - const columnsController = await getColumnsController(); - const expandColumns: Column[] = [groupExpandColumn]; - - const result = mergeColumns(columnsController, expandColumns, [{ dataField: 'a' }]); - - expect(result).toEqual(expandColumns); - expect(result[0]).not.toBe(expandColumns[0]); - }); - - it('should apply the options of a groupExpand column but keep the position of the expand column', async () => { - const columnsController = await getColumnsController(); - const column: Column = { - type: 'groupExpand', - index: 5, - visibleIndex: 6, - headerId: 'dx-col-5', - groupIndex: 3, - cssClass: 'custom', - width: 50, - caption: 'Group', - }; - - const result = mergeColumns(columnsController, [groupExpandColumn], [{ dataField: 'a' }, column]); - - expect(result).toEqual([{ - type: 'groupExpand', - command: 'expand', - index: 1, - visibleIndex: 2, - headerId: 'dx-col-1', - groupIndex: 0, - cssClass: 'custom', - width: 50, - caption: 'Group', - allowFixing: true, - allowReordering: true, - }]); - }); - - it.each([1, undefined])('should forbid fixing and reordering when groupIndex is %s', async (groupIndex) => { - const columnsController = await getColumnsController(); - - const [column] = mergeColumns( - columnsController, - [{ ...groupExpandColumn, groupIndex }], - [{ type: 'groupExpand' }], - ); - - expect(column.allowFixing).toBe(false); - expect(column.allowReordering).toBe(false); - }); - - it('should let a column of another type override every option', async () => { - const columnsController = await getColumnsController(); - - const [column] = mergeColumns( - columnsController, - [{ - type: 'detailExpand', command: 'expand', index: 1, visibleIndex: 2, - }], - [{ - type: 'detailExpand', index: 5, visibleIndex: 6, width: 40, - }], - ); - - expect(column).toEqual({ - type: 'detailExpand', command: 'expand', index: 5, visibleIndex: 6, width: 40, - }); - }); - - it('should not treat a groupExpand column as the expand command column', async () => { - const columnsController = await getColumnsController(); - - const [column] = mergeColumns( - columnsController, - [{ type: 'groupExpand', command: 'expand', index: 1 }], - [{ type: 'expand', caption: 'Expand' }], - ); - - expect(column).toEqual({ type: 'groupExpand', command: 'expand', index: 1 }); - }); - }); -}); - describe('processBandColumns', () => { beforeEach(beforeTest); afterEach(afterTest); @@ -1706,12 +1392,9 @@ describe('processBandColumns', () => { editing: { mode: 'row', allowUpdating: true }, columns: ['a', { caption: 'Band', columns: ['b', { type: 'buttons' }] }], }); - const columns = mergeColumns( - columnsController, - columnsController.getColumns(), - columnsController._commandColumns, - true, - ); + const columns = copyColumns(columnsController).map((column): Column => ( + column.type === 'buttons' ? { ...column, command: 'edit' } : column + )); processBandColumns(columnsController, columns, columnsController.getBandColumnsCache()); diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts index 0f50b32c3016..6bd64cce4c57 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts @@ -73,6 +73,7 @@ import { getChildrenByBandColumn, getColumnByIndexes, getColumnIndexByVisibleIndex, + getCommandColumnIndex, getCustomizeTextByDataType, getDataColumns, getFixedPosition, @@ -85,7 +86,6 @@ import { isColumnNameRequired, isFirstOrLastColumn, isSortOrderValid, - mergeColumns, numberToString, processBandColumns, processExpandColumns, @@ -835,9 +835,75 @@ export class ColumnsController extends modules.Controller { }); } + private mergeColumns( + columns: Column[], + commandColumns: Column[], + needToExtend?: boolean, + ): Column[] { + const isColumnFixing = this._isColumnFixing(); + let defaultCommandColumns = commandColumns.map( + (commandColumn) => extend({ fixed: isColumnFixing }, commandColumn) as Column, + ); + + const mergedColumns = columns.map((column): Column => { + const isGroupExpandColumn = column.type === GROUP_COMMAND_COLUMN_NAME; + const commandColumnIndex = getCommandColumnIndex( + column, + commandColumns, + needToExtend && isGroupExpandColumn, + ); + + if (commandColumnIndex < 0) { + return extend({}, column); + } + + const commandColumn = commandColumns[commandColumnIndex]; + + if (needToExtend) { + if (!isGroupExpandColumn) { + defaultCommandColumns = defaultCommandColumns.filter( + ({ command }) => command !== commandColumn.command, + ); + } + + return extend( + { fixed: isColumnFixing }, + commandColumn, + column, + { + calculateCellValue: commandColumn.calculateCellValue, + cssClass: [commandColumn.cssClass ?? '', column.cssClass ?? ''].join(' ').trim(), + }, + ) as Column; + } + + const columnOptions = { + visibleIndex: column.visibleIndex, + index: column.index, + headerId: column.headerId, + allowFixing: column.groupIndex === 0, + allowReordering: column.groupIndex === 0, + groupIndex: column.groupIndex, + }; + + return extend( + {}, + column, + commandColumn, + isGroupExpandColumn && columnOptions, + ) as Column; + }); + + if (columns.length && needToExtend && defaultCommandColumns.length) { + return mergedColumns.concat(defaultCommandColumns); + } + + return mergedColumns; + } + private _compileVisibleColumnsCore(): Column[][] { const bandColumnsCache = this.getBandColumnsCache(); - const columns: Column[] = mergeColumns(this, this._columns, this._commandColumns, true); + const columns: Column[] = this.mergeColumns(this._columns, this._commandColumns, true); processBandColumns(this, columns, bandColumnsCache); @@ -945,7 +1011,7 @@ export class ColumnsController extends modules.Controller { }: IndexedColumns): Column[][] { const result: Column[][] = []; const rowCount: number = this.getRowCount(); - const expandColumns: Column[] = mergeColumns(this, this.getExpandColumns(), this._columns); + const expandColumns: Column[] = this.mergeColumns(this.getExpandColumns(), this._columns); // Process header rows columns for (let rowIndex = 0; rowIndex < rowCount; rowIndex += 1) { diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts index 760b3df5099f..8916d8b93c63 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts @@ -1035,73 +1035,6 @@ export const getCommandColumnIndex = ( ); }; -export const mergeColumns = ( - that: ColumnsController, - columns: Column[], - commandColumns: Column[], - needToExtend?: boolean, -): Column[] => { - const isColumnFixing = that._isColumnFixing(); - let defaultCommandColumns = commandColumns.map( - (commandColumn) => extend({ fixed: isColumnFixing }, commandColumn) as Column, - ); - - const mergedColumns = columns.map((column): Column => { - const isGroupExpandColumn = column.type === GROUP_COMMAND_COLUMN_NAME; - const commandColumnIndex = getCommandColumnIndex( - column, - commandColumns, - needToExtend && isGroupExpandColumn, - ); - - if (commandColumnIndex < 0) { - return extend({}, column); - } - - const commandColumn = commandColumns[commandColumnIndex]; - - if (needToExtend) { - if (!isGroupExpandColumn) { - defaultCommandColumns = defaultCommandColumns.filter( - ({ command }) => command !== commandColumn.command, - ); - } - - return extend( - { fixed: isColumnFixing }, - commandColumn, - column, - { - calculateCellValue: commandColumn.calculateCellValue, - cssClass: [commandColumn.cssClass ?? '', column.cssClass ?? ''].join(' ').trim(), - }, - ) as Column; - } - - const columnOptions = { - visibleIndex: column.visibleIndex, - index: column.index, - headerId: column.headerId, - allowFixing: column.groupIndex === 0, - allowReordering: column.groupIndex === 0, - groupIndex: column.groupIndex, - }; - - return extend( - {}, - column, - commandColumn, - isGroupExpandColumn && columnOptions, - ) as Column; - }); - - if (columns.length && needToExtend && defaultCommandColumns.length) { - return mergedColumns.concat(defaultCommandColumns); - } - - return mergedColumns; -}; - export const isColumnFixed = (that: ColumnsController, column: Column): boolean => { const isFixedCommandColumn = column.type && column.type !== AI_COLUMN_NAME; From 000fb2d7cf79091647d78ee204aa207f81c7e9b7 Mon Sep 17 00:00:00 2001 From: Aliar666 Date: Fri, 4 Dec 2026 20:51:10 +0400 Subject: [PATCH 3/6] Grids: ColumnsController - move isColumnFixed and getFixedPosition into the class --- .../columns_controller_utils.test.ts | 44 ------------------- .../columns_controller/columns_controller.ts | 29 ++++++++++-- .../columns_controller_utils.ts | 27 +----------- 3 files changed, 27 insertions(+), 73 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts index 7d3e21c5138b..8a619d7b0e1f 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller_utils.test.ts @@ -25,7 +25,6 @@ import { getDataColumns, getSerializationFormat, getValueDataType, - isColumnFixed, numberToString, processBandColumns, reserveGroupIndex, @@ -671,49 +670,6 @@ describe('createColumnsFromDataSourceAdapter', () => { }); }); -describe('isColumnFixed', () => { - beforeEach(beforeTest); - afterEach(afterTest); - - describe('when the column is not a command column', () => { - it('should return true for a fixed column', async () => { - const columnsController = await getColumnsController(); - - expect(isColumnFixed(columnsController, { fixed: true })).toBe(true); - }); - - it('should return false for a sticky column', async () => { - const columnsController = await getColumnsController(); - const column: Column = { fixed: true, fixedPosition: 'sticky' }; - - expect(isColumnFixed(columnsController, column)).toBe(false); - }); - - it.each([ - ['a data column', {}], - ['an AI column', { type: 'ai' }], - ])('should ignore the column fixing of the grid for %s', async (_, column: Column) => { - const columnsController = await getColumnsController(); - jest.spyOn(columnsController, '_isColumnFixing').mockReturnValue(true); - - expect(isColumnFixed(columnsController, column)).toBe(false); - }); - }); - - describe('when the column is a command column', () => { - it.each([ - [true, true], - [false, false], - [false, undefined], - ])('should return %s when the column fixing of the grid is %s', async (expected, isColumnFixing) => { - const columnsController = await getColumnsController(); - jest.spyOn(columnsController, '_isColumnFixing').mockReturnValue(isColumnFixing); - - expect(isColumnFixed(columnsController, { type: 'buttons' })).toBe(expected); - }); - }); -}); - describe('findColumn', () => { it('should return undefined when the identifier is undefined', () => { expect(findColumn([{ index: 0 }], undefined)).toBeUndefined(); diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts index 6bd64cce4c57..55b8361b6c97 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts @@ -76,13 +76,11 @@ import { getCommandColumnIndex, getCustomizeTextByDataType, getDataColumns, - getFixedPosition, getParentBandColumns, getRowCount, getSerializationFormat, getValueDataType, hasCellValueCalculator, - isColumnFixed, isColumnNameRequired, isFirstOrLastColumn, isSortOrderValid, @@ -675,7 +673,7 @@ export class ColumnsController extends modules.Controller { notFixedColumnCount += 1; transparentColumnIndex ??= j; } else if (prevColumn && prevColumn.fixed - && getFixedPosition(this, prevColumn) !== getFixedPosition(this, column)) { + && this.getFixedPosition(prevColumn) !== this.getFixedPosition(column)) { transparentColumnIndex ??= j; } else { lastFixedPosition = column.fixedPosition; @@ -718,6 +716,29 @@ export class ColumnsController extends modules.Controller { return isColumnFixing; } + private isColumnFixed(column: Column): boolean { + const isFixedCommandColumn = column.type && column.type !== AI_COLUMN_NAME; + + if (isFixedCommandColumn) { + return !!this._isColumnFixing(); + } + + return !!column.fixed && column.fixedPosition !== StickyPosition.Sticky; + } + + private getFixedPosition(column: Column): FixedPosition { + const isDefaultCommandColumn = column.command + && !gridCoreUtils.isCustomCommandColumn(this._columns, column); + + if (isDefaultCommandColumn || !column.fixedPosition) { + const rtlEnabled = this.option('rtlEnabled'); + + return rtlEnabled ? 'right' : 'left'; + } + + return column.fixedPosition; + } + /** * @extended: master_detail */ @@ -1176,7 +1197,7 @@ export class ColumnsController extends modules.Controller { if (!targetColumn || column.ownerBand !== targetColumn.ownerBand) { options.visibleIndex = Number.MAX_SAFE_INTEGER; - } else if (isColumnFixed(this, column) !== isColumnFixed(this, targetColumn)) { + } else if (this.isColumnFixed(column) !== this.isColumnFixed(targetColumn)) { options.visibleIndex = Number.MAX_SAFE_INTEGER; } else { options.visibleIndex = targetColumn.visibleIndex; diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts index 8916d8b93c63..324d518de72a 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts @@ -1,7 +1,7 @@ import type { DataType, HorizontalAlignment, SortOrder } from '@js/common'; import type { Format } from '@js/common/core/localization'; import numberLocalization from '@js/common/core/localization/number'; -import type { ColumnBase, ColumnCustomizeTextArg, FixedPosition } from '@js/common/grids'; +import type { ColumnBase, ColumnCustomizeTextArg } from '@js/common/grids'; import { normalizeIndexes } from '@js/core/utils/array'; import { equalByValue } from '@js/core/utils/common'; import { compileGetter, compileSetter } from '@js/core/utils/data'; @@ -21,7 +21,7 @@ import { CLASSES as COLUMN_HEADERS_CLASSES } from '@ts/grids/grid_core/column_he import { AI_COLUMN_NAME } from '../ai_column/const'; import type DataSourceAdapter from '../data_source_adapter/data_source_adapter'; import type { RawItemData } from '../data_source_adapter/types'; -import { StickyPosition } from '../sticky_columns/const'; +import type { StickyPosition } from '../sticky_columns/const'; import { getColumnFixedPosition } from '../sticky_columns/utils'; import gridCoreUtils from '../utils'; import type { ColumnsController } from './columns_controller'; @@ -964,19 +964,6 @@ export const getRowCount = (that: ColumnsController): number => { return rowCount; }; -export const getFixedPosition = (that: ColumnsController, column: Column): FixedPosition => { - const isDefaultCommandColumn = column.command - && !gridCoreUtils.isCustomCommandColumn(that._columns, column); - - if (isDefaultCommandColumn || !column.fixedPosition) { - const rtlEnabled = that.option('rtlEnabled'); - - return rtlEnabled ? 'right' : 'left'; - } - - return column.fixedPosition; -}; - export const processExpandColumns = ( columns: Column[], expandColumns: Column[], @@ -1035,16 +1022,6 @@ export const getCommandColumnIndex = ( ); }; -export const isColumnFixed = (that: ColumnsController, column: Column): boolean => { - const isFixedCommandColumn = column.type && column.type !== AI_COLUMN_NAME; - - if (isFixedCommandColumn) { - return !!that._isColumnFixing(); - } - - return !!column.fixed && column.fixedPosition !== StickyPosition.Sticky; -}; - export const convertOwnerBandToColumnReference = (columns: Column[]): void => { columns.forEach((column) => { if (isDefined(column.ownerBand)) { From 3cdd55bd512fbe1b67691ef2d87b06901f2c73bc Mon Sep 17 00:00:00 2001 From: Aliar666 Date: Fri, 4 Dec 2026 20:52:27 +0400 Subject: [PATCH 4/6] Grids: ColumnsController - move isFirstOrLastColumn into the class --- .../columns_controller/columns_controller.ts | 80 ++++++++++++++++++- .../columns_controller_utils.ts | 79 ------------------ 2 files changed, 77 insertions(+), 82 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts index 55b8361b6c97..202401186598 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts @@ -56,6 +56,7 @@ import type { Module } from '@ts/grids/grid_core/types'; import { AI_COLUMN_NAME } from '../ai_column/const'; import modules from '../modules/modules'; import { StickyPosition } from '../sticky_columns/const'; +import { getColumnFixedPosition } from '../sticky_columns/utils'; import gridCoreUtils from '../utils'; import { addExpandColumn, @@ -82,7 +83,6 @@ import { getValueDataType, hasCellValueCalculator, isColumnNameRequired, - isFirstOrLastColumn, isSortOrderValid, numberToString, processBandColumns, @@ -2357,13 +2357,87 @@ export class ColumnsController extends modules.Controller { return parentColumns.at(parentColumnIndex); } + private isFirstOrLastColumnCore( + column: Column, + rowIndex: number | null, + onlyWithinBandColumn = false, + isLast = false, + fixedPosition?: StickyPosition, + ): boolean { + const getColumns = (index: number | null): Column[] => this.getVisibleColumns(index) + .filter((col) => { + if (this.isAdaptiveHiddenColumn(col)) { + return false; + } + + if (onlyWithinBandColumn) { + return col.ownerBand === column.ownerBand; + } + + if (fixedPosition) { + return !!col.fixed && getColumnFixedPosition(this, col) === fixedPosition; + } + + return true; + }); + + const columnIndex = column.index; + const columns = getColumns(rowIndex); + const visibleColumnIndex = this.getVisibleIndex(columnIndex, rowIndex); + + return isLast + ? visibleColumnIndex === this.getVisibleIndex(columns[columns.length - 1]?.index, rowIndex) + : visibleColumnIndex === this.getVisibleIndex(columns[0]?.index, rowIndex); + } + + private isFirstOrLastBandColumn( + bandColumns: Column[], + onlyWithinBandColumn = false, + isLast = false, + fixedPosition?: StickyPosition, + ): boolean { + return bandColumns.every((column, index) => (onlyWithinBandColumn && index === 0) + || this.isFirstOrLastColumnCore(column, index, onlyWithinBandColumn, isLast, fixedPosition)); + } + + private isFirstOrLastColumn( + targetColumn: Column, + rowIndex: number | null, + onlyWithinBandColumn = false, + isLast = false, + fixedPosition?: StickyPosition, + ): boolean { + const targetColumnIndex = targetColumn.index; + const bandColumnsCache = this.getBandColumnsCache(); + const parentBandColumns = isDefined(targetColumn.type) + ? [] + : getParentBandColumns(targetColumnIndex, bandColumnsCache.columnParentByIndex); + + if (parentBandColumns.length) { + return this.isFirstOrLastBandColumn( + parentBandColumns.concat([targetColumn]), + onlyWithinBandColumn, + isLast, + fixedPosition, + ); + } + + return onlyWithinBandColumn || this.isFirstOrLastColumnCore( + targetColumn, + rowIndex, + onlyWithinBandColumn, + isLast, + fixedPosition, + ); + } + public isFirstColumn( column: Column, rowIndex: number | null, onlyWithinBandColumn = false, fixedPosition?: StickyPosition, ): boolean { - return isFirstOrLastColumn(this, column, rowIndex, onlyWithinBandColumn, false, fixedPosition); + return this.isFirstOrLastColumn(column, rowIndex, onlyWithinBandColumn, false, fixedPosition); } public isLastColumn( @@ -2372,7 +2446,7 @@ export class ColumnsController extends modules.Controller { onlyWithinBandColumn = false, fixedPosition?: StickyPosition, ): boolean { - return isFirstOrLastColumn(this, column, rowIndex, onlyWithinBandColumn, true, fixedPosition); + return this.isFirstOrLastColumn(column, rowIndex, onlyWithinBandColumn, true, fixedPosition); } public isCustomCommandColumn(commandColumn: Column): boolean { diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts index 324d518de72a..fd1848b2adc9 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller_utils.ts @@ -21,8 +21,6 @@ import { CLASSES as COLUMN_HEADERS_CLASSES } from '@ts/grids/grid_core/column_he import { AI_COLUMN_NAME } from '../ai_column/const'; import type DataSourceAdapter from '../data_source_adapter/data_source_adapter'; import type { RawItemData } from '../data_source_adapter/types'; -import type { StickyPosition } from '../sticky_columns/const'; -import { getColumnFixedPosition } from '../sticky_columns/utils'; import gridCoreUtils from '../utils'; import type { ColumnsController } from './columns_controller'; import { @@ -1098,83 +1096,6 @@ export const strictParseNumber = (text: string, format: Format): number | undefi return undefined; }; -const isFirstOrLastColumnCore = ( - that: ColumnsController, - column: Column, - rowIndex: number | null, - onlyWithinBandColumn = false, - isLast = false, - fixedPosition?: StickyPosition, -): boolean => { - const getColumns = (index: number | null): Column[] => that.getVisibleColumns(index) - .filter((col) => { - if (that.isAdaptiveHiddenColumn(col)) { - return false; - } - - if (onlyWithinBandColumn) { - return col.ownerBand === column.ownerBand; - } - - if (fixedPosition) { - return !!col.fixed && getColumnFixedPosition(that, col) === fixedPosition; - } - - return true; - }); - - const columnIndex = column.index; - const columns = getColumns(rowIndex); - const visibleColumnIndex = that.getVisibleIndex(columnIndex, rowIndex); - - return isLast - ? visibleColumnIndex === that.getVisibleIndex(columns[columns.length - 1]?.index, rowIndex) - : visibleColumnIndex === that.getVisibleIndex(columns[0]?.index, rowIndex); -}; - -const isFirstOrLastBandColumn = ( - that: ColumnsController, - bandColumns: Column[], - onlyWithinBandColumn = false, - isLast = false, - fixedPosition?: StickyPosition, -): boolean => bandColumns.every((column, index) => (onlyWithinBandColumn && index === 0) - || isFirstOrLastColumnCore(that, column, index, onlyWithinBandColumn, isLast, fixedPosition)); - -export const isFirstOrLastColumn = ( - that: ColumnsController, - targetColumn: Column, - rowIndex: number | null, - onlyWithinBandColumn = false, - isLast = false, - fixedPosition?: StickyPosition, -): boolean => { - const targetColumnIndex = targetColumn.index; - const bandColumnsCache = that.getBandColumnsCache(); - const parentBandColumns = isDefined(targetColumn.type) - ? [] - : getParentBandColumns(targetColumnIndex, bandColumnsCache.columnParentByIndex); - - if (parentBandColumns.length) { - return isFirstOrLastBandColumn( - that, - parentBandColumns.concat([targetColumn]), - onlyWithinBandColumn, - isLast, - fixedPosition, - ); - } - - return onlyWithinBandColumn || isFirstOrLastColumnCore( - that, - targetColumn, - rowIndex, - onlyWithinBandColumn, - isLast, - fixedPosition, - ); -}; - export const isColumnNameRequired = (column: Column): boolean => ( COMMAND_COLUMNS_WITH_REQUIRED_NAMES.includes(column.type ?? '') ); From 5a95e7b64459507b13ee42386ff1289c88bd5901 Mon Sep 17 00:00:00 2001 From: Aliar666 Date: Fri, 4 Dec 2026 20:53:22 +0400 Subject: [PATCH 5/6] Grids: ColumnsController - make isAdaptiveHiddenColumn protected --- .../adaptivity/extenders/adaptivity_columns_controller.ts | 2 +- .../grids/grid_core/columns_controller/columns_controller.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/adaptivity/extenders/adaptivity_columns_controller.ts b/packages/devextreme/js/__internal/grids/grid_core/adaptivity/extenders/adaptivity_columns_controller.ts index 65e491bbab3e..3d140e2ae72d 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/adaptivity/extenders/adaptivity_columns_controller.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/adaptivity/extenders/adaptivity_columns_controller.ts @@ -24,7 +24,7 @@ export const adaptivityColumnsControllerExtender = ( .filter((column) => !hasHiddenWidth(column)); } - public isAdaptiveHiddenColumn(column: Column): boolean { + protected isAdaptiveHiddenColumn(column: Column): boolean { return super.isAdaptiveHiddenColumn(column) || this.adaptiveColumnsController.isColumnHidden(column); } diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts index 202401186598..c7f30862813b 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/columns_controller.ts @@ -2505,7 +2505,7 @@ export class ColumnsController extends modules.Controller { * @extended: adaptivity */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - public isAdaptiveHiddenColumn(column: Column): boolean { + protected isAdaptiveHiddenColumn(column: Column): boolean { return false; } } From 4ef789956e31101ee832c944f0b0a2d46b3d935b Mon Sep 17 00:00:00 2001 From: Aliar666 Date: Sat, 5 Dec 2026 04:12:45 +0400 Subject: [PATCH 6/6] Fix comments --- .../columns_controller.visible_columns.test.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts index 9e1eeb1a2889..3aa44db912a6 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/__tests__/columns_controller.visible_columns.test.ts @@ -174,7 +174,9 @@ describe('getVisibleColumns', () => { }); describe('with grouping', () => { - const DATA_SOURCE = [{ a: 1, b: 2, c: 3 }]; + const DATA_SOURCE = [{ + id: 1, a: 1, b: 2, c: 3, + }]; const GROUPED_COLUMNS: ColumnOptions[] = ['a', { dataField: 'b', groupIndex: 0 }, { dataField: 'c', groupIndex: 1 }]; it('should apply the options of a groupExpand column to every group column', async () => { @@ -250,7 +252,7 @@ describe('getVisibleColumns', () => { it('should let a detailExpand column override every option of the detail expand column', async () => { const columnsController = await getColumnsController({ - dataSource: [{ a: 1 }], + dataSource: [{ id: 1, a: 1 }], columns: ['a', { type: 'detailExpand', width: 40 }], masterDetail: { enabled: true }, }); @@ -288,10 +290,9 @@ describe('moveColumn', () => { }); it('should move a column to the end when the target column is fixed and the column is not', async () => { - const [a, b, c] = await moveColumn({ columns: [{ dataField: 'a', fixed: true }, 'b', 'c'] }, 2, 0); + const [, b, c] = await moveColumn({ columns: [{ dataField: 'a', fixed: true }, 'b', 'c'] }, 1, 0); - expect(c).toBeGreaterThan(a); - expect(c).toBeGreaterThan(b); + expect(b).toBeGreaterThan(c); }); it('should not treat a sticky column as fixed', async () => { @@ -306,8 +307,9 @@ describe('moveColumn', () => { ['a data column', 'c'], ['an AI column', AI_COLUMN], ])('should ignore the column fixing of the grid for %s', async (_, target) => { - const [a, , c] = await moveColumn({ columns: ['a', 'b', target], columnFixing: { enabled: true } }, 0, 2); + const [a, b, c] = await moveColumn({ columns: ['a', 'b', target], columnFixing: { enabled: true } }, 0, 2); + expect(a).toBeGreaterThan(b); expect(a).toBeLessThan(c); }); @@ -322,11 +324,12 @@ describe('moveColumn', () => { }); it('should treat a command column as not fixed when the column fixing of the grid is disabled', async () => { - const [a, , buttons] = await moveColumn({ + const [a, b, buttons] = await moveColumn({ columns: ['a', 'b', { type: 'buttons' }], ...EDITING, }, 0, 2); + expect(a).toBeGreaterThan(b); expect(a).toBeLessThan(buttons); }); });