Closed abdulrehmananwar closed 1 month ago
Hi @abdulrehmananwar ,
In SfDataGrid, when you attempt to edit a cell, the focus shifts to the TextField loaded in the buildEditWidget. When the focus moves to the TextField, key events are no longer handled by the DataGrid. In SfDataGrid, we handle key events such as Enter (to submit the cell) and Tab (for navigation) during editing. If you want to handle the Ctrl+V key event, you will need to add a Focus widget as the parent of the TextField and perform the action as needed.
Additionally, we have attached the user guide documentation for key behaviors handled by SfDataGrid, along with code snippets for your reference. Please review these code snippets for more details and adapt them to suit your specific requirements.
UG link - Keyboard behavior
Code snippets:
@override
Widget? buildEditWidget(DataGridRow dataGridRow,
RowColumnIndex rowColumnIndex, GridColumn column, CellSubmit submitCell) {
final String displayText = dataGridRow
.getCells()
.firstWhereOrNull((DataGridCell dataGridCell) =>
dataGridCell.columnName == column.columnName)
?.value
?.toString() ??
'';
newCellValue = null;
final bool isNumericType =
column.columnName == 'ID' || column.columnName == 'Salary';
return Container(
padding: const EdgeInsets.all(8.0),
alignment: isNumericType ? Alignment.centerRight : Alignment.centerLeft,
child: Focus(
onKeyEvent: (node, keyEvent) {
if (keyEvent.logicalKey == LogicalKeyboardKey.keyA) {
if (HardwareKeyboard.instance.isControlPressed) {
// Execute the necessary action.
return KeyEventResult.handled;
}
}
return KeyEventResult.ignored;
},
child: TextField(
autofocus: true,
controller: editingController..text = displayText,
textAlign: isNumericType ? TextAlign.right : TextAlign.left,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 8.0),
),
keyboardType:
isNumericType ? TextInputType.number : TextInputType.text,
onChanged: (String value) {
if (value.isNotEmpty) {
if (isNumericType) {
newCellValue = int.parse(value);
} else {
newCellValue = value;
}
} else {
newCellValue = null;
}
},
onSubmitted: (String value) {
submitCell();
},
),
),
);
}
Regards, Abinesh P
Hi @abdulrehmananwar,
We suspect that the reported issue has been resolved at your end. We are closing this issue now. If you need any further assistance, reopen this issue. We are always happy to assist you.
Regards, Ashok k
Bug description
hey i am using Flutter DataGrid (SfDataGrid) with two editable cells now i was not able to capture event on CustomSelectionManager Future handleKeyEvent(KeyEvent keyEvent) async { print('keyevent');} it only print i case of tab and enter not for others
Steps to reproduce
i cannot able to detect paste event when cell is into input
Code sample
please provide sample code
Screenshots or Video
not this time
Stack Traces
please provide sample code
On which target platforms have you observed this bug?
Windows
Flutter Doctor output
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.22.3, on Microsoft Windows [Version 10.0.19045.4651], locale en-US) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.10.4) [√] Android Studio (version 2023.3) [√] Connected device (3 available) [√] Network resources