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

3 posts, 0 answers
  1. Joshua
    Joshua avatar
    6 posts
    Member since:
    Aug 2016

    Posted 14 Nov 2016 Link to this post

    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. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    1049 posts

    Posted 15 Nov 2016 Link to this post

    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.
  3. Stephen
    Stephen avatar
    90 posts
    Member since:
    Jan 2011

    Posted 17 Nov 2016 Link to this post

    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.

Back to Top