We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

how to change enter key behavior datagrid flutter

i need some help or examples on how to use this 



1 Reply

TP Tamilarasan Paranthaman Syncfusion Team October 7, 2022 01:28 PM UTC

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


Loader.
Live Chat Icon For mobile
Up arrow icon