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

How to raise datasource's error event in Kendo

1 Answer 574 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 18 Jan 2018, 03:48 PM

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

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 23 Jan 2018, 07:50 AM
Hello Brandon,

A possible solution is to trigger the error event manually.

e.g.

dataSource.trigger('error');

Then, to revert the newly applied changes in the dataSource call the cancelChanges method of the grid within the error event handler of the dataSource.


Regards,
Georgi
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
Grid
Asked by
Brandon
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or