Advertisement
sanjay1909

Two Situations to access Spark Datagrid New value

Sep 28th, 2014
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Scenario one
  2. // -------------
  3. // Dataprovider is set of objects
  4. // Datafield of Gridcolumn is mapped with object properties
  5. // Now we can access the new value from dataprovider.
  6. import spark.components.DataGrid;
  7.  
  8. var sparkDataGrid:DataGrid = new DataGrid();
  9. sparkDataGrid.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE, handleGridItemEditEnd);
  10.                    
  11. private function handleGridItemEditEnd(event:GridItemEditorEvent):void
  12. {
  13.     var newValue:String = (event.currentTarget as CustomSparkDataGrid).dataProvider[event.rowIndex][event.columnIndex];
  14. }
  15.  
  16.  
  17. // Scenario Two
  18. // -------------
  19. // Dataprovider is set of objects
  20. // Label function to set custom cell-display value and datafield is not mapped
  21. // Label function return value, take precedence as dataField is Null
  22. // so we can't access the new value from dataprovider
  23. import spark.components.DataGrid;
  24. import spark.components.gridClasses.GridItemEditor;
  25. import spark.components.gridClasses.IGridItemEditor;
  26.  
  27. var sparkDataGrid:DataGrid = new DataGrid();
  28. sparkDataGrid.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE, handleGridItemEditEnd);
  29.  
  30. private var destroyedItemEditor:IGridItemEditor;
  31.  
  32. // Griditem Editor - gets destroyed  before dispatching the save event -
  33. // So its important to get its reference .
  34. private function handleGridItemEditStart(event:GridItemEditorEvent):void
  35. {
  36.     destroyedItemEditor = (event.currentTarget as DataGrid).itemEditorInstance;            
  37. }
  38.  
  39. // Griditem Editor - gets destroyed  before dispatching the save event -
  40. // hence itemEditorInstance will be null at this stage
  41. // We can't access the value from dataprovider as we use label function to set the cell display ,
  42. // instead of dataField value
  43. private function handleGridItemEditEnd(event:GridItemEditorEvent):void
  44. {
  45.     if(destroyedItemEditor){
  46.         // As IGrid Itemeditor doesn't provide getter method to access value
  47.         // we have to cast as base class to get the value property
  48.         // It important for us, to make sure when we create our own custom editor , it extends Grid item editor base class
  49.         // and override getter and setter of value method
  50.         var newValue:String = (destroyedItemEditor as GridItemEditor).value as String;             
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement