0 Replies Latest reply on Feb 20, 2013 5:37 AM by Abhinav Sharma

    mx:AdvancedDataGrid - Expand Item on Rendererer Click - Using itemIndex

    Abhinav Sharma Level 2

      Hello,

       

      I am trying to expand an item in AdvancedDataGrid (ADG) from a Custom Spark ItemRenderer's event. There's just a Button in that renderer.

       

      Dataprovider HierarchicalData(ArrayCollection). Max Depth is 2.

       

      new ArrayCollection([
        {id: 1, source:"NODE 1", state: "Done", children:[  
         {detail:[{time:5},{time:10},{time:20},{time:45}]}]},
        {id: 2, source:"NODE 2", state: "Done", children:[  
         {detail:[{time:5},{time:10},{time:20},{time:45}]}]},
        {id: 3, source:"NODE 3", state: "Done", children:[  
         {detail:[{time:5},{time:10},{time:20},{time:45}]}]},
        {id: 5, source:"NODE 4", state: "Done", children:[  
         {detail:[{time:5},{time:10},{time:20},{time:45}]}]}
         ]}
      ]); 
      

       

       

      To expand nodes I have written a custom Renderer with a single Button as of now. (Would add other items in future)

       

      adg-e1.JPG

       

       

      What I need?

       

      On click of button, I need to expand the item corresponding to that row.

       

       

      The Issue?

       

      I am using itemIndex property from the renderer to tell ADG to which node to be expanded.

       

      1st time when I click it works fine. But after that, due to Expand operation now new Items are added in ADG. So the itemIndex that the Button renderer has [0,1,2,3] are still the initial ones and will not satisfy the next expand operation.

       

      Below code snippet to handle expand request: //dont know if it is the best way or not. Google has made me to reach this

       

      public function toggleGridItem(event:AdvGridEvent):void //AdvGridEvent is custom Event
       {
        var colllectionObj:Object = HierarchicalCollectionView(myADG.dataProvider).source.getRoot();
        
        Alert.show("Index: "+event.index + ", Expand: "+event.expand);
        var targetNode:Object = ListCollectionView(colllectionObj).getItemAt(event.index);
        
        //event.expand = true|false
        myADG.expandItem(targetNode, event.expand);
       }
      

       

       

      My Question?

       

      1. Is there any way to Expand Items on the Events triggered from renderers inside the ADG?

      2. Can we trace the ADG's Row from any ItemRenderer (knowing that itemIndex is not getting updated on Node expansion, so it will not help)? I want the row index to get my task done.

       

       

      Any help is appreciated.

       

      thanks,

      Abhinav