Need to capture Delete keyboard key before record deleted

Hello, I have a toolbar button for Delete and I have set <GridEditSettings AllowDeleting="true"/>. When the user clicks the Delete toolbar button, I capture it in the ToolbarClickHandler and I ask the user to confirm the deletion of the record by asking them to enter their password. All works great until the user clicks the Delete keyboard button. The SfGrid deletes the row immediately. I can capture the "onkeyup" and ask the same question as above to the user for confirmation but I just cannot prevent the grid from deleting the row even when the user fails to confirm the deletion. How do I prevent the grid from deleting the row straight away on Delete keyboard key no matter what? Many thanks.
 

5 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team April 9, 2021 04:20 AM UTC

Hi Saeed, 
 
Greetings from Syncfusion support. 
 
We have validated your query and you can cancel the Delete action by using the OnActionBegin event of the grid. We suggest you to set args.Cancel as true based on the request type of the corresponding action. 
 
    public void ActionBegin(ActionEventArgs<OrdersDetails> args) 
    { 
        if(args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete)) 
        { 
            args.Cancel = true; 
        } 
    } 
 
 
Please refere the below documentation for your reference. 
 
 
Regards, 
Jeevakanth SP. 


Marked as answer

SD Saeed Dudhia April 12, 2021 09:00 AM UTC

Thanks Jeevakanth - that works.

Regards, Saeed.



JP Jeevakanth Palaniappan Syncfusion Team April 13, 2021 05:05 AM UTC

Hi Saeed, 

Thanks for the update. Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 



SA Salvatore February 13, 2023 09:49 AM UTC

Hi

if in the ActionBeginHandler, rendered async void, a function with await is called (to ask for confirmation via the classic javascript confirm function call) the setting of args.Cancel = true does not work and the line is canceled anyway.


looking forward to your kind reply

Greetings




MS Monisha Saravanan Syncfusion Team February 14, 2023 12:25 PM UTC


Hi Salvatore,


Greetings from Syncfusion support.


Based on your description, it sounds like you are experiencing an issue with the cancellation of a line of code in the ActionBeginHandler when using an async void function with await to confirm an action using the classic JavaScript confirm function.


In this scenario, we would recommend using an asynchronous Task function function instead of an async void function. This will allow you to use the await keyword and properly cancel the line of code using the args.Cancel = true statement.


public async Task ActionBeginHandler(ActionEventArgs<Order> args)

    {

        // Here, you can customize your code.

    }


I hope this helps. If we misunderstood your query then kindly share the below details to proceed further at our end.


  1. Share us the entire Grid code snippet.
  2. Share us the video demonstration of the issue you are facing.
  3. If possible share us the simple issue reproducing sample.


Above requested details will be very helpful in validating the reported query at our end and provide solution as early as possible.


Regards,

Monisha



Loader.
Up arrow icon