I just remembered that I had trouble finding out what I could access with this event handler function. Sure it was easy to find out when the event is dispatched, but how can I access the new field value edited by the user? How do I access the previous value?
So this is just a simple example showing you that. This also applies to the normal DataGrid and standard list controls.
The itemEditEnd event is dispatched (it’s in the name) when a user finishes editing a cell so this is pretty much the best time to save the user’s changes to that field/row.
Here’s our function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | protected function saveChange(event:AdvancedDataGridEvent):void { /** * use event.dataField to get the edited field name */ var field:String = event.dataField; /** * i'm using the following line to get the 'id' of the row being edited * because i passed an 'id' field through from my dataProvider. */ var selectedID:String = event.currentTarget.selectedItem.id.toString(); /** * use the itemEditorInstance to get the newly edited value but retrieve * the previous value from the existing grid data. i'm using the default * textinput itemRenderer so I can retrieve the new value using the * itemEditInstance's 'text' property. */ var newValue:String = event.currentTarget.itemEditorInstance.text; var prevValue:String = ProductPersonalisationList.selectedItem[event.dataField]; // run a http service call or something to save the change or validate the data } |
#1 by SGIA on 12 February, 2009 - 10:13 am
Quote
Thanks for this post.
event.currentTarget.itemEditorInstance.text was exactly what I was after.
#2 by ANKUR on 31 March, 2009 - 6:54 pm
Quote
U rock dude………………………..
#3 by Daniel on 24 April, 2009 - 4:44 am
Quote
Awesome post. This saved me so much time. Thanks!
#4 by epilefserdna on 28 August, 2009 - 9:10 pm
Quote
THANK YOU VERY MUCH!!!. You saved my day.