Hi Sami,
Currently, DataGrid support to override the handleKeyEvent methods in RowSelectionManager class to customize the key navigation/operation in DataGrid and set the instance to the SfDataGrid.selectionManager. We have prepared a sample for that. In that sample, we changed the DataGrid Enter key behavior to select a specific record instead of moving to the next focused row/cell in the DataGrid using DataGridController. Please check the following sample and code snippet.
|
late EmployeeDataSource _employeeDataSource; List<Employee> _employees = <Employee>[];
class _SfDataGridDemoState extends State<SfDataGridDemo> { DataGridController dataGridController = DataGridController(); late CustomSelectionManager customSelectionManager;
@override void initState() { super.initState(); _employees = getEmployeeData(); _employeeDataSource = EmployeeDataSource(_employees); customSelectionManager = CustomSelectionManager(dataGridController); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Syncfusion Flutter SfDataGrid')), body: SfDataGrid( source: _employeeDataSource, columns: getColumns, controller: dataGridController, selectionMode: SelectionMode.single, selectionManager: customSelectionManager, columnWidthMode: ColumnWidthMode.fill)); } }
class CustomSelectionManager extends RowSelectionManager { CustomSelectionManager(this.dataGridController); DataGridController dataGridController; @override void handleKeyEvent(RawKeyEvent keyEvent) { if (keyEvent.logicalKey == LogicalKeyboardKey.enter) { dataGridController.selectedRow = _employeeDataSource.dataGridRow[4];
//You can write your logic return; } super.handleKeyEvent(keyEvent); } } |
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/sample-369020756
Note: The actual behavior of the enter key is the current cell or row will be moved to the next focused row of the same column.
We have already considered customising the key event extensively as a feature. We will implement this feature in any one of our upcoming releases. At the planning stage for every release cycle, we review all open features. We will let you know when this feature is implemented. You can follow up with the below feedback for further follow-up,
Feedback Link: https://www.syncfusion.com/feedback/29709/expose-the-required-apis-in-rowselectionmanager-class-to-customize-extensively
We hope this helps. In case we misunderstood your requirement, please provide more specific or clear use case details. It will be helpful for us to check and provide an appropriate solution.
Regards,
Tamilarasan