I have Kendo grid that is configured for batch edit as per the demo. Instead of making 3 separate calls to server for Create, Update and Delete I am handling the SaveChange event of the grid to save all changes ( to maintain transaction)
var grid = $("#grid").getKendoGrid();
grid.bind("saveChanges", function (e) {
var data = grid.dataSource.data();
// collect updated rows and new rows
var items = $.grep(data, function (item) {
return item.dirty || item.id === 0;
})
// collect deleted rows
$.each(grid.dataSource._destroyed, function (index, item) {
item.IsDeleted = true;
items.push(item);
})
$.ajax({
type: "POST",
data: items,
url: "save",
contentType: "application/json; charset=utf-8",
processData: true,
cache: false,
})
.done(function (response, textStatus, jqXHR) {
// do something
})
.fail(function (jqXHR, textStatus, errorThrown) {
// How do i inform datasource or grid about error
})
})
If there is an error on server while saving changes, the datasource does not know about it. How do i inform datasource ( or trigger error in datasource) that the save operation is failed?
Right now if there is an Error during save, datasource does not know about it and datasource sets updated record's dirty property to false and also clears dataSource._destroyed collection. Beacuase of that if after error user clicks SaveChanges again, the above code will only find records with id zero