Articles in this section
Category / Section

How to perform an action using shortcut keys in Flutter DataTable?

2 mins read

In this article, we will show you how to perform an action using shortcut keys for buttons in Flutter DataTable.

Initialize the SfDataGrid widget with all necessary properties. By using the handleKeyEvent() method in the RowSelectionManager with selection enabled, we can fetch the respective row details based on the currentCell when the Fn key is pressed. To perform an action using Fn keys for buttons, you need to maintain the currentCell on the button cells. Based on the key pressed, we perform the respective action for the corresponding button.

  @override
  Future<void> handleKeyEvent(KeyEvent keyEvent) async {
    // Only trigger for the button columns when the current cell is in the button column.
    // So we have checked the columnIndex == 3.
    if (keyEvent.logicalKey == LogicalKeyboardKey.f1 &&
        dataGridController.currentCell.columnIndex == 3) {
      // To show the respective Button1 row details when F1 is pressed.
      handleButton1Pressed();

      return;
    } else if (keyEvent.logicalKey == LogicalKeyboardKey.f2 &&
        dataGridController.currentCell.columnIndex == 3) {
      // To show the respective Button2 row details when F2 is pressed.
      handleButton2Pressed();

      return;
    }
    super.handleKeyEvent(keyEvent);
  }

View the GitHub sample here.

Conclusion

I hope you enjoyed learning about how to perform an action using shortcut keys in Flutter DataTable.

You can refer to our Flutter DataTable feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Flutter DataTable example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied