-
Notifications
You must be signed in to change notification settings - Fork 672
DataGrid: Implementing reordering of grouped columns using keyboard navigation #29628
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
Alyar666
merged 13 commits into
DevExpress:25_1
from
Alyar666:grid_group_column_reordering_with_keyboard_25_1
Apr 24, 2025
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a7c00d5
Extract event subscriptions to the core part
71d0074
Implement reordering of group columns using keyboard
7a6ac08
Fix focus reset when clicking on grouping column
64615af
Add etalons
b8971e3
Fix issue with fixed columns reordering when there is a command colum…
3edd6cc
Update the storybook example
a5bc7b6
Add etalons
e44b00c
Update etalon
33605cc
Remove the debugger from tests
8c33a9d
Fix the column reordering when allowColumnReordering is false and gro…
9f7c3a7
Make group column reordering via keyboard dependent on groupPanel.all…
13cbea7
code refactoring
5e1a250
Add etalons
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
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...tcafe-devextreme/tests/dataGrid/common/keyboardNavigation/groupColumnReordering.visual.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,101 @@ | ||
| import { createScreenshotsComparer } from 'devextreme-screenshot-comparer'; | ||
| import DataGrid from 'devextreme-testcafe-models/dataGrid'; | ||
| import url from '../../../../helpers/getPageUrl'; | ||
| import { createWidget } from '../../../../helpers/createWidget'; | ||
|
|
||
| fixture | ||
| .disablePageReloads`Keyboard Navigation - Group Column Reordering` | ||
| .page(url(__dirname, '../../../container.html')); | ||
|
|
||
| const DATA_GRID_SELECTOR = '#container'; | ||
|
|
||
| // Group columns | ||
| [true, false].forEach((rtlEnabled) => { | ||
| test(`reorder group column when ${rtlEnabled ? 'left' : 'right'} arrow is pressed when rtlEnabled = ${rtlEnabled}`, async (t) => { | ||
| const { takeScreenshot, compareResults } = createScreenshotsComparer(t); | ||
| const dataGrid = new DataGrid(DATA_GRID_SELECTOR); | ||
| const firstGroupHeader = dataGrid.getGroupPanel().getHeader(0); | ||
| const shortcut = rtlEnabled ? 'ctrl+left' : 'ctrl+right'; | ||
|
|
||
| await t | ||
| .click(firstGroupHeader.element) | ||
| .pressKey(shortcut); | ||
|
|
||
| await takeScreenshot( | ||
| `reorder_group_column_to_${rtlEnabled ? 'left' : 'right'}_when_rtlEnabled_=_${rtlEnabled}`, | ||
| dataGrid.element, | ||
| ); | ||
|
|
||
| await t.expect(compareResults.isValid()) | ||
| .ok(compareResults.errorMessages()); | ||
| }).before(async () => { | ||
| await createWidget('dxDataGrid', { | ||
| rtlEnabled, | ||
| dataSource: [{ | ||
| field1: 'test1', | ||
| field2: 'test2', | ||
| field3: 'test3', | ||
| field4: 'test4', | ||
| }], | ||
| groupPanel: { | ||
| visible: true, | ||
| }, | ||
| columns: [ | ||
| { | ||
| dataField: 'field1', | ||
| groupIndex: 1, | ||
| }, | ||
| 'field2', | ||
| 'field3', | ||
| { | ||
| dataField: 'field4', | ||
| groupIndex: 0, | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| test(`reorder group column when ${rtlEnabled ? 'right' : 'left'} arrow is pressed when rtlEnabled = ${rtlEnabled}`, async (t) => { | ||
| const { takeScreenshot, compareResults } = createScreenshotsComparer(t); | ||
| const dataGrid = new DataGrid(DATA_GRID_SELECTOR); | ||
| const lastGroupHeader = dataGrid.getGroupPanel().getHeader(1); | ||
| const shortcut = rtlEnabled ? 'ctrl+right' : 'ctrl+left'; | ||
|
|
||
| await t | ||
| .click(lastGroupHeader.element) | ||
| .pressKey(shortcut); | ||
|
|
||
| await takeScreenshot( | ||
| `reorder_group_column_to_${rtlEnabled ? 'right' : 'left'}_when_rtlEnabled_=_${rtlEnabled}`, | ||
| dataGrid.element, | ||
| ); | ||
|
|
||
| await t.expect(compareResults.isValid()) | ||
| .ok(compareResults.errorMessages()); | ||
| }).before(async () => { | ||
| await createWidget('dxDataGrid', { | ||
| rtlEnabled, | ||
| dataSource: [{ | ||
| field1: 'test1', | ||
| field2: 'test2', | ||
| field3: 'test3', | ||
| field4: 'test4', | ||
| }], | ||
| groupPanel: { | ||
| visible: true, | ||
| }, | ||
| columns: [ | ||
| { | ||
| dataField: 'field1', | ||
| groupIndex: 1, | ||
| }, | ||
| 'field2', | ||
| 'field3', | ||
| { | ||
| dataField: 'field4', | ||
| groupIndex: 0, | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
| }); |
7 changes: 7 additions & 0 deletions
7
packages/devextreme/js/__internal/grids/data_grid/grouping/const.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,7 @@ | ||
| export const CLASSES = { | ||
| groupPanel: 'dx-datagrid-group-panel', | ||
| groupPanelMessage: 'dx-group-panel-message', | ||
| groupPanelItem: 'dx-group-panel-item', | ||
| groupPanelLabel: 'dx-toolbar-label', | ||
| groupPanelContainer: 'dx-toolbar-item', | ||
| }; |
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
95 changes: 95 additions & 0 deletions
95
...me/js/__internal/grids/data_grid/keyboard_navigation/m_group_panel_keyboard_navigation.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,95 @@ | ||
| import { | ||
| isCommandKeyPressed, | ||
| } from '@js/common/core/events/utils/index'; | ||
| import $ from '@js/core/renderer'; | ||
| import { Direction } from '@ts/grids/grid_core/keyboard_navigation/const'; | ||
| import { KeyboardNavigationController as KeyboardNavigationControllerCore } from '@ts/grids/grid_core/keyboard_navigation/m_keyboard_navigation_core'; | ||
| import type { Views } from '@ts/grids/grid_core/m_types'; | ||
|
|
||
| import { CLASSES as GROUPING_CLASSES } from '../grouping/const'; | ||
| import gridCore from '../m_core'; | ||
|
|
||
| export class GroupPanelKeyboardNavigationController extends KeyboardNavigationControllerCore { | ||
| protected headerPanel!: Views['headerPanel']; | ||
|
|
||
| private isGroupColumnValidForReordering(groupColumn, direction: Direction): boolean { | ||
| const groupedColumns = this._columnsController.getGroupColumns(); | ||
|
|
||
| return direction === Direction.Next | ||
| ? groupColumn.index !== groupedColumns[groupedColumns.length - 1].index | ||
| : groupColumn.index !== groupedColumns[0].index; | ||
| } | ||
|
|
||
| private leftRightKeysHandler(e): void { | ||
| const { originalEvent } = e; | ||
|
|
||
| if (isCommandKeyPressed(originalEvent)) { | ||
| const groupColumn: any = $(originalEvent.target).data('columnData'); | ||
| const direction = this.getDirectionByKeyName(e.keyName); | ||
|
|
||
| if (this.isGroupColumnValidForReordering(groupColumn, direction)) { | ||
| const newGroupIndex = direction === Direction.Next | ||
| ? groupColumn.groupIndex + 2 | ||
|
Alyar666 marked this conversation as resolved.
|
||
| : groupColumn.groupIndex - 1; | ||
| const newFocusedGroupColumnIndex = direction === Direction.Next | ||
| ? groupColumn.groupIndex + 1 | ||
| : groupColumn.groupIndex - 1; | ||
|
|
||
| this.isNeedToFocus = true; | ||
| this.setFocusedCellPosition(0, newFocusedGroupColumnIndex); | ||
| this._columnsController.columnOption( | ||
| groupColumn.index, | ||
| 'groupIndex', | ||
| newGroupIndex, | ||
| ); | ||
| } | ||
|
|
||
| originalEvent?.preventDefault(); | ||
| } | ||
| } | ||
|
|
||
| protected _getCell(cellPosition): any { | ||
| const $groupColumnElements = this.headerPanel?.getColumnElements(); | ||
|
|
||
| return $groupColumnElements?.eq(cellPosition.columnIndex); | ||
| } | ||
|
|
||
| protected getFocusedView() { | ||
| return this.getView('headerPanel'); | ||
| } | ||
|
|
||
| protected getFocusedViewElement() { | ||
| return this.headerPanel?.element()?.find(`.${GROUPING_CLASSES.groupPanel}`); | ||
| } | ||
|
|
||
| protected getFocusinSelector(): string { | ||
| return `.${GROUPING_CLASSES.groupPanelItem}`; | ||
| } | ||
|
|
||
| protected keyDownHandler(e): void { | ||
| const isHandled = this.processOnKeyDown(e); | ||
|
|
||
| if (isHandled) { | ||
| return; | ||
| } | ||
|
|
||
| // eslint-disable-next-line default-case | ||
| switch (e.keyName) { | ||
|
Alyar666 marked this conversation as resolved.
Outdated
|
||
| case 'leftArrow': | ||
| case 'rightArrow': | ||
| this.leftRightKeysHandler(e); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| public init(): void { | ||
| this.headerPanel = this.getView('headerPanel'); | ||
| super.init(); | ||
| } | ||
| } | ||
|
|
||
| gridCore.registerModule('groupPanelKeyboardNavigation', { | ||
| controllers: { | ||
| groupPanelKeyboardNavigation: GroupPanelKeyboardNavigationController, | ||
| }, | ||
| }); | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.