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
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?
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
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?
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);
});
}
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