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

Destroy methods removes item from datasource without server check

3 Answers 402 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jakub
Top achievements
Rank 1
Jakub asked on 04 Apr 2016, 08:11 PM

Hello

Iam using datasource in kendoGrid. Kendogrid has mode inline, so I can edit add and delete rows. To each method I use my own ajax calls. The problem is that If I delete row, then row is deleted from datasource and then the call to destroy function is made. Thats why I cannot prevent user from deleting this row as it may fail on server side. Is there any option to make it work to say to datasource, first wait for server response then delete row if server succeeded?

Example:

http://dojo.telerik.com/UMUSu/2

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 06 Apr 2016, 10:35 AM

Hello Jakub,

Indeed, this is the designed behavior of the widget. However, you should use the DataSource cancelChanges method inside the error event handler in order to revert the deleted record. For example:

error: function(e)
{
    this.cancelChanges();
    alert('error');
}

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jakub
Top achievements
Rank 1
answered on 08 Apr 2016, 08:33 PM
This generates another problem as it will delete my row, then after I will get response from WebApi and cancel changes, the datasource will add element to grid. Its not acceptable:

http://dojo.telerik.com/UMUSu/4
0
Rosen
Telerik team
answered on 11 Apr 2016, 10:20 AM

Hello Jakub,

Indeed, this is how it is designed to work. As I have mentioned in my previous message, the cancelChanges method will revert changes, making the deleted record to appear in the Grid again.

When given record is deleted it is removed from the DataSource's data thus, it is removed from the Grid content. Then when the DataSource is synced this record is actually send to the server for deletion. Therefore, with this event flow, it is only possible reverted back, not to prevent it from "disappearing", from the DataSource data when a server error during sync call occurs.

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