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

Remove a row, call sync, but keep row in grid until success response from destroy

2 Answers 839 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 14 Nov 2016, 06:23 PM

Right now I'm working through removing an item from the grid. I can't seem to find a way to use the destroy transport to mark a row as one that should be deleted, make a request to delete those rows, and only if those rows were successfully deleted from by a service, THEN visually remove the row from the grid. Everything I try (grid.removeRow, dataSource.remove, dataSource.sync) just removes the row from the grid right away, before the request is made to the server to remove the row. I need the ability to notify the user of a failed attempt to remove those rows, and keep those rows displayed if the service was unable to delete those rows.

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 15 Nov 2016, 09:24 AM
Hello Joshua,

The desired functionality is not supported, as removing an item from the Grid's dataSource, and removing it from the actual database are two distinct operations that, in current Grid implementation, are happening in such order that the item is removed from the dataSource before it is removed from the database.

A possible approach to achieve the desired behavior would be to handle deleting of items manually, e.g.  performing a custom AJAX request to delete an item, then call the dataSource.read() method in the success callback to visually reflect the made changes in the Grid. I hope this helps.

Regards,
Dimiter Topalov
Telerik by Progress
Build rich, delightful, *native* Angular 2 apps with Kendo UI for Angular 2. Try it out today! Kendo UI for Angular 2 (currently in beta) is a jQuery-free toolset, written in TypeScript, designed from the ground up to offer true, native Angular 2 components.
0
Stephen
Top achievements
Rank 2
answered on 17 Nov 2016, 03:45 PM

Just thinking out loud here....

I might try adding a Deleted flag to the model.  When the user selects the row to be deleted, set Deleted = true(update styling as desired) instead of removing the row.

Then when the grid is submitted, the Deleted = true rows would be submitted as an update.

In the server's update action, delete the rows from the DB where Deleted = true AND remove them from the datasource result response passed back to the grid.  I don't know if the grid will actually remove these rows from the UI, but it is worth a try.  If it doesn't, then you can either force the dataSource.read() to get a fresh, updated dataset or manually remove the Deleted = true rows from the datasource and then clear the dataSource's destroyed collection...basically entirely bypass the built-in destroyed handling.

Tags
Grid
Asked by
Joshua
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Stephen
Top achievements
Rank 2
Share this question
or