Repository navigation
Grids: type m_grid_view #35598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
anna-shakhova
merged 5 commits into
DevExpress:main
from
anna-shakhova:type_grid_view_main
Oct 12, 2026
Merged
Grids: type m_grid_view #35598
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ee1646e
Grids: type m_grid_view
anna-shakhova 46132bf
Grids: improve readability m_grid_view
anna-shakhova 69689e2
Grids: cleanup found small issues
anna-shakhova 2e96f95
Grids: drop Object.create from free width tests
anna-shakhova c6c042d
rebase
anna-shakhova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...me/js/__internal/grids/grid_core/views/__tests__/grid_view.free_width.integration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import { | ||
| afterEach, beforeEach, describe, expect, it, | ||
| } from '@jest/globals'; | ||
| import $ from '@js/core/renderer'; | ||
| import type { Properties as DataGridProperties } from '@js/ui/data_grid'; | ||
|
|
||
| import type { DataGridInstance } from '../../__tests__/__mock__/helpers/utils'; | ||
| import { | ||
| afterTest, beforeTest, createDataGrid, | ||
| } from '../../__tests__/__mock__/helpers/utils'; | ||
| import type { ColumnWidth } from '../types'; | ||
|
|
||
| const CONTENT_WIDTH = 1000; | ||
|
|
||
| const createGrid = async ( | ||
| columns: DataGridProperties['columns'] = [], | ||
| ): Promise<DataGridInstance> => { | ||
| const { instance } = await createDataGrid({ dataSource: [], columns }); | ||
|
|
||
| $(instance.getView('rowsView').element()).css('width', `${CONTENT_WIDTH}px`); | ||
|
|
||
| return instance; | ||
| }; | ||
|
|
||
| const getAverageColumnsWidth = async (resultWidths: ColumnWidth[]): Promise<number> => { | ||
| const instance = await createGrid(); | ||
| const resizingController = instance.getController('resizing'); | ||
|
|
||
| // @ts-expect-error _getAverageColumnsWidth is private | ||
| return resizingController._getAverageColumnsWidth(resultWidths); | ||
| }; | ||
|
|
||
| const correctColumnWidths = async ( | ||
| columns: DataGridProperties['columns'], | ||
| resultWidths: ColumnWidth[], | ||
| ): Promise<{ isCorrected: boolean; resultWidths: ColumnWidth[] }> => { | ||
| const instance = await createGrid(columns); | ||
| const resizingController = instance.getController('resizing'); | ||
| const visibleColumns = instance.getController('columns').getVisibleColumns(); | ||
|
|
||
| // @ts-expect-error _correctColumnWidths is protected | ||
| const isCorrected = resizingController._correctColumnWidths(resultWidths, visibleColumns); | ||
|
|
||
| return { isCorrected, resultWidths }; | ||
| }; | ||
|
|
||
| describe('ResizingController._getAverageColumnsWidth', () => { | ||
| beforeEach(beforeTest); | ||
| afterEach(afterTest); | ||
|
|
||
| it('splits the free width between the columns without a width', async () => { | ||
| const averageWidth = await getAverageColumnsWidth([200, undefined, 300, undefined]); | ||
|
|
||
| expect(averageWidth).toBe(250); | ||
| }); | ||
|
|
||
| it('subtracts percent widths resolved against the content width', async () => { | ||
| const averageWidth = await getAverageColumnsWidth(['30%', 200, undefined]); | ||
|
|
||
| expect(averageWidth).toBe(500); | ||
| }); | ||
|
|
||
| it('returns a negative width when the set widths exceed the content width', async () => { | ||
| const averageWidth = await getAverageColumnsWidth([700, 500, undefined]); | ||
|
|
||
| expect(averageWidth).toBe(-200); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ResizingController._correctColumnWidths', () => { | ||
| beforeEach(beforeTest); | ||
| afterEach(afterTest); | ||
|
|
||
| describe('a column without a width and with minWidth', () => { | ||
| it('gets its minWidth when the free width is smaller', async () => { | ||
| const result = await correctColumnWidths( | ||
| [{ dataField: 'a', minWidth: 400 }, { dataField: 'b', width: 700 }], | ||
| [undefined, 700], | ||
| ); | ||
|
|
||
| expect(result).toEqual({ isCorrected: true, resultWidths: [400, 700] }); | ||
| }); | ||
|
|
||
| it('keeps no width when the free width fits its minWidth', async () => { | ||
| const result = await correctColumnWidths( | ||
| [{ dataField: 'a', minWidth: 200 }, { dataField: 'b', width: 700 }], | ||
| [undefined, 700], | ||
| ); | ||
|
|
||
| expect(result).toEqual({ isCorrected: false, resultWidths: [undefined, 700] }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('a percent column with minWidth', () => { | ||
| it('gets its minWidth when its percent width is smaller', async () => { | ||
| const result = await correctColumnWidths( | ||
| [{ dataField: 'a', width: '30%', minWidth: 400 }, { dataField: 'b' }], | ||
| ['30%', undefined], | ||
| ); | ||
|
|
||
| expect(result).toEqual({ isCorrected: true, resultWidths: [400, undefined] }); | ||
| }); | ||
|
|
||
| it('keeps its percent width when it is wider than minWidth and minWidth fits', async () => { | ||
| const result = await correctColumnWidths( | ||
| [{ dataField: 'a', width: '50%', minWidth: 400 }, { dataField: 'b' }], | ||
| ['50%', undefined], | ||
| ); | ||
|
|
||
| expect(result).toEqual({ isCorrected: false, resultWidths: ['50%', undefined] }); | ||
| }); | ||
|
|
||
| it('gets its minWidth when minWidth does not fit, even if its percent width is wider', async () => { | ||
| const result = await correctColumnWidths( | ||
| [{ dataField: 'a', width: '150%', minWidth: 1200 }, { dataField: 'b' }], | ||
| ['150%', undefined], | ||
| ); | ||
|
|
||
| expect(result).toEqual({ isCorrected: true, resultWidths: [1200, undefined] }); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_updateScrollableTimeoutID was never set, so remove unnecessary method overload