Undo Functionality in Grid

2 posts, 0 answers
  1. Artur
    Artur avatar
    1 posts
    Member since:
    Jan 2016

    Posted 30 Jan 2016 Link to this post

        I've implemented an undo capability into the grid. If a user changes the value of a field but they want to reverse the change they will click on the undo button and the change is undone. This undo functionality remembers only the last change. I've implemented this using List's and by clearing out the grid and re-building the grid using the data in the lists. It works but it's slow. Imagine re-building a 2000 row X 800 column grid. I tried saving the previous state of the data in the grid in another datatable and then getting rid of the current datatable and making this datatable the current one but I ran into many problems.

    Is there a better way of doing this?


  2. Stefan
    Stefan avatar
    1073 posts

    Posted 01 Feb 2016 Link to this post

    Hello Artur,

    For this scenario, I suggest you modifying only the items of RadGridView that have been modified, rather than populating all items of the control on each undo operation. This can be achieved through the RowEditEnded event, as its GridViewRowEditEndedEventArgs expose an EditedItem property, as well a OldValues collection.

    Basically, if you need to perform an undo operation only for the last edited item, you can hold a reference to a single instance of your business model and set its properties based on the property values present in the OldValues collection within the aforementioned event handler. When the user performs an undo operation, you should be able set the values of the last edited item to be its old ones, as demonstrated in the How to undo changes after RowEditEnded forum thread.

    If such requirement is needed for a collection of modified items, you can simply modify the suggested approach by using a collection of the last edited elements, iterate through them and undo the values of the relevant items present within the Items collection of RadGridView.

    Hope this helps.

    All the best,
    Stefan X1
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top