-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataGrid: add Custom keyboard navigation topic (#5573)
- Loading branch information
1 parent
4b08261
commit b78dee6
Showing
5 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
1 change: 1 addition & 0 deletions
1
...ponents/DataGrid/70 Custom Keyboard Navigation/00 Custom Keyboard Navigation.md
This file contains 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 @@ | ||
You can use the [keyboardNavigation](/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/keyboardNavigation/) property to configure DataGrid [keyboard navigation](/Documentation/Guide/UI_Components/DataGrid/Accessibility/#Keyboard_Navigation). If the default behavior does not meet your requirements, you can change it. |
90 changes: 90 additions & 0 deletions
90
...ts/DataGrid/70 Custom Keyboard Navigation/05 Change the Default Focused Cell.md
This file contains 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,90 @@ | ||
To specify cell focus order when a user navigates through DataGrid, call the [onFocusedCellChanging](https://js.devexpress.com/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/#onFocusedCellChanging) function. The code below uses `newColumnIndex` to set the column index of the next focused cell. | ||
|
||
--- | ||
##### jQuery | ||
|
||
<!-- tab: index.js --> | ||
$("#dataGridContainer").dxDataGrid({ | ||
// ... | ||
onFocusedCellChanging: function (e) { | ||
if (e.columns[e.newColumnIndex].dataField === "myField") { // Checks if the next focused cell is in the 'myField' column | ||
e.newColumnIndex++; // Navigates to the next column | ||
} | ||
} | ||
}); | ||
|
||
##### Angular | ||
|
||
<!-- tab: app.component.html --> | ||
<dx-data-grid ... | ||
(onFocusedCellChanging)="onFocusedCellChanging($event)"> | ||
</dx-data-grid> | ||
|
||
<!-- tab: app.component.ts --> | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
|
||
export class AppComponent { | ||
onFocusedCellChanging(e) { | ||
if (e.columns[e.newColumnIndex].dataField === "myField") { // Checks if the next focused cell is in the 'myField' column | ||
e.newColumnIndex++; // Navigates to the next column | ||
} | ||
} | ||
} | ||
|
||
##### Vue | ||
|
||
<!-- tab: App.vue --> | ||
<template> | ||
<DxDataGrid ... | ||
@focused-cell-changing="onFocusedCellChanging"> | ||
</DxDataGrid> | ||
</template> | ||
|
||
<script> | ||
import 'devextreme/dist/css/dx.light.css'; | ||
import DxDataGrid from 'devextreme-vue/data-grid'; | ||
|
||
export default { | ||
components: { | ||
DxDataGrid | ||
}, | ||
// ... | ||
methods: { | ||
onFocusedCellChanging(e) { | ||
if (e.columns[e.newColumnIndex].dataField === "myField") { // Checks if the next focused cell is in the 'myField' column | ||
e.newColumnIndex++; // Navigates to the next column | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
##### React | ||
|
||
<!-- tab: App.js --> | ||
import React from 'react'; | ||
import 'devextreme/dist/css/dx.light.css'; | ||
import DataGrid from 'devextreme-react/data-grid'; | ||
|
||
const onFocusedCellChanging = (e) => { | ||
if (e.columns[e.newColumnIndex].dataField === "myField") { // Checks if the next focused cell is in the 'myField' column | ||
e.newColumnIndex++; // Navigates to the next column | ||
} | ||
} | ||
|
||
function App() { | ||
return ( | ||
<DataGrid ... | ||
onFocusedCellChanging={onFocusedCellChanging}> | ||
</DataGrid> | ||
); | ||
} | ||
export default App; | ||
|
||
--- |
7 changes: 7 additions & 0 deletions
7
...onents/DataGrid/70 Custom Keyboard Navigation/10 Focus Cells Programatically.md
This file contains 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 @@ | ||
You can call the following methods to focus a cell: | ||
|
||
- [focus](/Documentation/ApiReference/UI_Components/dxDataGrid/Methods/#focuselement) | ||
Allows you to move focus to a cell. Call the [getCellElement](/Documentation/ApiReference/UI_Components/dxDataGrid/Methods/#getCellElementrowIndex_dataField) method to obtain a cell container. Then, pass the container to the **focus** method as an argument to focus the target cell. | ||
|
||
- [editCell](/Documentation/ApiReference/UI_Components/dxDataGrid/Methods/#editCellrowIndex_dataField) | ||
Switches a cell to the edit state and moves focus to this cell. |
105 changes: 105 additions & 0 deletions
105
...omponents/DataGrid/70 Custom Keyboard Navigation/15 Override and Create Keys.md
This file contains 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,105 @@ | ||
The [onKeyDown](/Documentation/ApiReference/UI_Components/dxDataGrid/Configuration/#onKeyDown) event handler allows you to track pressed keystrokes while the UI component has focus. You can use the event handler to override the default keyboard shortcuts, implement custom keystrokes, or extend existing ones. | ||
|
||
The following example shows how to override the **Space Bar** keystroke so it switches a cell in cell/batch mode to the edit state instead of a current row select operation: | ||
|
||
--- | ||
##### jQuery | ||
|
||
<!-- tab: index.js --> | ||
$("#dataGridContainer").dxDataGrid({ | ||
// ... | ||
onKeyDown: function (e) { | ||
if (e.event.keyCode === 32) { // Checks if the space bar key is pressed | ||
e.event.preventDefault(); // Prevents the default behavior | ||
const focusedRowIndex = e.component.option("focusedRowIndex"); | ||
const focusedColumnIndex = e.component.option("focusedColumnIndex"); | ||
e.component.editCell(focusedRowIndex, focusedColumnIndex); | ||
} | ||
} | ||
}) | ||
|
||
##### Angular | ||
|
||
<!-- tab: app.component.html --> | ||
<dx-data-grid ... | ||
(onKeyDown)="onKeyDown($event)"> | ||
</dx-data-grid> | ||
|
||
<!-- tab: app.component.ts --> | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
|
||
export class AppComponent { | ||
onKeyDown(e) { | ||
if (e.event.keyCode === 32) { // Checks if the space bar key is pressed | ||
e.event.preventDefault(); // Prevents the default behavior | ||
const focusedRowIndex = e.component.option("focusedRowIndex"); | ||
const focusedColumnIndex = e.component.option("focusedColumnIndex"); | ||
e.component.editCell(focusedRowIndex, focusedColumnIndex); | ||
} | ||
} | ||
} | ||
|
||
##### Vue | ||
|
||
<!-- tab: App.vue --> | ||
<template> | ||
<DxDataGrid ... | ||
@key-down="onKeyDown"> | ||
</DxDataGrid> | ||
</template> | ||
|
||
<script> | ||
import 'devextreme/dist/css/dx.light.css'; | ||
import DxDataGrid from 'devextreme-vue/data-grid'; | ||
|
||
export default { | ||
components: { | ||
DxDataGrid | ||
}, | ||
// ... | ||
methods: { | ||
onKeyDown(e) { | ||
if (e.event.keyCode === 32) { // Checks if the space bar key is pressed | ||
e.event.preventDefault(); // Prevents the default behavior | ||
const focusedRowIndex = e.component.option("focusedRowIndex"); | ||
const focusedColumnIndex = e.component.option("focusedColumnIndex"); | ||
e.component.editCell(focusedRowIndex, focusedColumnIndex); | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
##### React | ||
|
||
<!-- tab: App.js --> | ||
import React from 'react'; | ||
import 'devextreme/dist/css/dx.light.css'; | ||
import DataGrid from 'devextreme-react/data-grid'; | ||
|
||
const onKeyDown = (e) => { | ||
if (e.event.keyCode === 32) { // Specifies if the space bar key is pressed | ||
e.event.preventDefault(); // Prevents the default behavior | ||
const focusedRowIndex = e.component.option("focusedRowIndex"); | ||
const focusedColumnIndex = e.component.option("focusedColumnIndex"); | ||
e.component.editCell(focusedRowIndex, focusedColumnIndex); | ||
} | ||
} | ||
|
||
function App() { | ||
return ( | ||
<DataGrid ... | ||
onKeyDown={onKeyDown}> | ||
</DataGrid> | ||
); | ||
} | ||
|
||
export default App; | ||
|
||
--- |