I am working Apache Flex 4.11 web application. I have a DataGrid which has item renderer for change the record. Now I change the record in the Datagrid using item renderer. Now there is a cancel button out side the DataGrid when I click on that it should remove the local changes(which I have done it for change the record) and show the original data which is showing before the change.
How can I do that.
Thanks Bikrant Singh
1st) Make a copy/backup of your dataProvider's data, not a reference copy, but a true deep copy, do this before you allow the user to start editing.
If you were using an ArrayCollection, you could use the Flex based ObjectUtil:
VectorCollection does not have a clone/copy (need to verify this...), but you can easily sub-class it and add a AMF-based (via byteArray) deep-copy, 5/6s line of code for that...
2nd) On your Cancel button click eventHandler:
Note: This is from memory as I do not have AS3/Flex on this machine but should be pretty close...
Update:
Shallow copy a vector:
Deep copy (just change it to a vector instead of a dynamic object for performance):
Note: If you are creating a vector of some complex class/object, you might need to register these class(es)... Again from memory, so adjust as needed...