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

Undo Functionality in Grid

1 Answer 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Artur
Top achievements
Rank 1
Artur asked on 30 Jan 2016, 08:16 PM

Hello,
    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?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 01 Feb 2016, 03:35 PM
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
Telerik
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
Tags
GridView
Asked by
Artur
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or