This is a migrated thread and some comments may be shown as answers.

How to cancel destroy action in JS

3 Answers 704 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Maciej
Top achievements
Rank 1
Maciej asked on 13 Apr 2018, 05:48 PM

I'm calling options.error() in my destroy function but the row is removed anyway. How to prevent that ?

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Untitled</title>
 
 
<body>
  <div class='grid'><div>
    <script>
      $(".grid").kendoGrid({
        editable:
        {
          mode: "inline",
          confirmation: false
        },
        dataSource:
        {
          transport:
          {
            read: options =>
            {
              options.success([{test: "test", id: 1}]);
            },
            destroy: options =>{
              options.error("error")
            }
          },
          schema:
          {
            model:
            {
              id: "id"
            }
          }
        },
        columns:
        [{
          field: "test"
        },
         {
           command: ["destroy"]
         }]
      })
    </script>
</body>
</html>

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 Apr 2018, 06:40 AM
Hello, Maciej,

Thank you for the code.

This is expected because there are may be different reasons for why the delete is not possible. For example, if the item does not longer exist in the database because it was removed from somewhere else.

Once the error is returned, the error function of the dataSource will be called and the developer has full control over how to handle this on the client side:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/events/error

In this case, we can suggest making a new read to retrieve the correct items from the server:

https://dojo.telerik.com/ETuyEveh

Also, the requests can be prevented during the requestStart event:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/events/requeststart

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Maciej
Top achievements
Rank 1
answered on 17 Apr 2018, 01:28 PM
I tried 'requestStart' event. I called preventDefault() but the row was deleted anyways.
0
Stefan
Telerik team
answered on 18 Apr 2018, 07:10 AM
Hello, Maciej,

Preventing the default behavior will stop the request to be made to the server, but it will still remove the row from the UI.

Currently, once the delete button is clicked, the row will be removed from the DOM, and the in order to show it again the Grid has to be refreshed(read to the server).

I can suggest submitting a feature request for an option to prevent removing of the row on the remove event, and based on its popularity we may implement it in a future release:

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/remove

http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-beta-feedback?category_id=170280

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Data Source
Asked by
Maciej
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Maciej
Top achievements
Rank 1
Share this question
or