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

Old destroy calls being remembered and called again

6 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 08 Feb 2016, 09:12 PM

This is my destroy function:

destroy: function (e) {

               console.log(e.data);

                api.post("api/myservice/Remove", e.data)
                         .then(
                          function success(response) {
                                 $('#grid').data('kendoGrid').dataSource.read();
                          },
                          function error(response) {
                           });
               }

Whenever I delete a row (let's say e1), any other future action (create/update/destroy) I do will trigger the deletion of e1 AGAIN. So if I create a new row, it would create the row (call the create function) AND delete the e1 row (which doesn't exist anymore, but somehow the value of e.data still remains). The deletion chain is cumulative, so if I were to delete a row e2, and then perform an action, then I would get a deletion of e1 and e2 AGAIN.

Anyone know what the problem is??

6 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 09 Feb 2016, 02:59 PM
After doing some research, it seems that this is due to not returning the deleted item's ID back to Kendo. However, I'm not returning anything in the case of creation/update either, and there are no problems with multiple function firing there. I will return the deleted item ID and see if it works.
0
Andy
Top achievements
Rank 1
answered on 09 Feb 2016, 03:29 PM

Solved, returned the ID and called e.success(response.data), and multiple delete calls are not firing anymore.

However, why is this issue solely with the delete function and not the creation/update?

0
Boyan Dimitrov
Telerik team
answered on 10 Feb 2016, 01:49 PM

Hello Andy,

 

Actually the id of the data item that is updated/create or deleted should be returned back to the client-side from the server. 

 

As mentioned in the CRUD Data Operations article the Kendo UI DataSource uses the ID value to determine whether a data item is new or existing. If the ID value is zero, it is assumed that the data item is new, so the create function is executed. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Andy
Top achievements
Rank 1
answered on 10 Feb 2016, 02:51 PM

Hi Boyan,

If that is the case, why are multiple create/update events not firing? I am not returning the ID of the created/updated items.

Could it be because I am actually calling transport.read after every create/update?

0
Andy
Top achievements
Rank 1
answered on 10 Feb 2016, 03:00 PM
My code for reference, it is using an angular factory called "api" to wrap $http calls
 
// updating record
update: function (e) {
    api.post("api/service/Update", e.data)
        .then(
        function success(response) {
            $('#grid').data('kendoGrid').dataSource.read();
        },
        function error(response) {
            $log.log("Error when updating data. Message: " + response.data.ExceptionMessage);
        });
},
// create record
create: function (e) {
    api.post("api/service/Add", e.data)
        .then(
        function success(response) {
            $('#grid').data('kendoGrid').dataSource.read();
        },
        function error(data, status) {
            $log.log("Error when creating data. Message: " + response.data.ExceptionMessage);
        });
}
// My Code for reference
// My Code for reference
0
Boyan Dimitrov
Telerik team
answered on 12 Feb 2016, 11:31 AM

Hello Andy,

 

As mentioned in the Local or Custom Transport CRUD Operations article when performing CRUD operations the success or error method of the function argument must be executed at the end.

 

After that the Kendo UI Grid is refreshed with the new/updated values, so basically there is no need of reading the data of the Kendo UI Grid (also this is an additional request to the server). 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or