Hi df,
Greetings from Syncfusion support.
Query 1 : 1. How to achieve this inside OnActionBegin, in general how to stop code execution
Based on your requirement, we have modified the sample. Please download the sample form the link below,
In the above sample, we have cancelled the save action by using the Args.Cancel in OnActionBegin handler. And to update the values to Grid, when clicking the Yes button in save confirmation dialog, we have use the EndEdit() method of Grid. Please refer the code below,
|
<SfDialog @bind-Visible="@ConfirmDlgVisible" IsModal="true" Width="400px" Target="#mygrid" ShowCloseIcon="true" ZIndex="1002"> @*set z-index more than edit dialog*@ ... <DialogButtons> <DialogButton Content="Yes" IsPrimary="true" OnClick="@SaveHideDialog" /> <DialogButton Content="No" OnClick="@HideDialog" /> </DialogButtons></SfDialog>
@code {
...
public void HideDialog(Object e)
{
...
}
public void SaveHideDialog(Object e)
{
this.ConfirmDlgVisible = false;
this.flag = true;
Grid.EndEdit(); //Save the changes to Grid programatically.
}
public async void OnActionBegin(ActionEventArgs<WeatherForecast> Args)
{
...
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
if (Args.Action == "Add")
{
//some code....
}
else if(!flag)
{
this.ConfirmDlgVisible = true; Args.Cancel = true; //cancel the save action
...
}
}
...
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit && flag)
{
flag = false;
}
}
...
}
|
We have validated your reported query. We have a similar option in SfDialog, which returns the action of the SfDialog Closed. Can detect the SfDialog close action in the OnClose eventArgs, using the ClosedBy argument which returns ("Escape"|| "Close Icon" || “User Action“) based on the SfDialog closed.
Escape: When the dialog is closed using the Esc key.
Close Icon: When the dialog is closed using the Close Icon.
User Action: When the dialog is closed using the Buttons.
Please check the above solution and let us know if it meets your requirements.
Query 3 : 3. Can we disable the Enter key to close the Edit dialog?
We are not clear about your scenario regarding this query. As based on the Query 1 , the edit dialog will remain open, even after pressing Enter key. So if you need assistance regarding this query, then kindly get back to us with a detailed description regarding this requirement and scenario. And also, we suggest you to use the @onkeypress event for the Grid component. This will be triggered when pressing key, so based on your scenario you can customize the codes in this handler.
| <SfGrid ID="mygrid" @ref="Grid" DataSource="@forecasts" @onkeypress="onkeypress" ...>
public void onkeypress(KeyboardEventArgs args){ }
|
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran