Hi Ssekamatte,
Greetings from Syncfusion support.
By default, pressing Enter key will trigger the save action in Grid. So, based on your requirement, we suggest you to prevent the Save action using args.Cancel in OnActionBegin handler, based on the Enter key press in SfNumericTextBox. In the below code, we have prevented save using args.Cancel in OnActionBegin based on the @onkeydown event handler bound to SfNumericTextBox.
Please refer and use the codes below,
<SfGrid TValue="Order" ID="Grid" ... >
...
<GridEvents OnActionBegin="OnActionBegin" TValue="Order"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Dialog">
<Template>
...
<SfNumericTextBox TValue="double" ... ID="Freight" @bind-Value=@(((Order) context).Freight) @onkeydown="onkeydown" >
</SfNumericTextBox>
</Template>
</GridEditSettings>
...
</SfGrid>
public bool flag = false;public void onkeydown(KeyboardEventArgs args){ if (args.Key == "Enter") { flag = true; }}public async Task OnActionBegin(ActionEventArgs<Order> args){ if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save && flag) { flag = false; args.Cancel = true; }} |
Query : when I add onkeypress in my grid events,I get the error as shown
We suggest you to bind the onkeypress to SfGrid instead of GridEvents, as like the below code.
<SfGrid TValue="Order" ... @onkeypress="KeyPressGrid"> ...</SfGrid>public void KeyPressGrid(){ }
|
Please get back to us if you need further assistance.
Regards,
Renjith R