Old destroy calls being remembered and called again

7 posts, 0 answers
  1. Andy
    Andy avatar
    22 posts
    Member since:
    Feb 2016

    Posted 08 Feb 2016 Link to this post

    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??

  2. Andy
    Andy avatar
    22 posts
    Member since:
    Feb 2016

    Posted 09 Feb 2016 in reply to Andy Link to this post

    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.
  3. Andy
    Andy avatar
    22 posts
    Member since:
    Feb 2016

    Posted 09 Feb 2016 in reply to Andy Link to this post

    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?

  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 10 Feb 2016 Link to this post

    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!
     
  5. Andy
    Andy avatar
    22 posts
    Member since:
    Feb 2016

    Posted 10 Feb 2016 in reply to Boyan Dimitrov Link to this post

    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?

  6. Andy
    Andy avatar
    22 posts
    Member since:
    Feb 2016

    Posted 10 Feb 2016 in reply to Andy Link to this post

    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
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 12 Feb 2016 Link to this post

    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!
     
Back to Top