1 Reply Latest reply on Oct 10, 2012 1:41 AM by Abhishek Chaudhary

    Array collection


      Hello Experts,


      The below code i have taken from http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_10.html.

      In the below code, Array data for hierarchical display is populated inside the program and handled successfully.

      My requirement is to handle the array information from SAP. I am able to send the data dynamically and view the information in the table format. However i cannot handle the "Children" property of the hierarchical display. Pls guide me.


      How i can handle the children property dynamically ?



      <?xml version="1.0"?>

      <!-- dpcontrols/adg/SimpleHierarchicalADGTreeColumn.mxml -->

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">




                import mx.collections.ArrayCollection;




      private var dpHierarchy:ArrayCollection = new ArrayCollection([

        {Region:"Southwest", children: [

           {Region:"Arizona", children: [

              {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},

              {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 

           {Region:"Central California", children: [

              {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 

           {Region:"Nevada", children: [

              {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 

           {Region:"Northern California", children: [

              {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},

              {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 

           {Region:"Southern California", children: [

              {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},

              {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}]}






          <mx:AdvancedDataGrid width="100%" height="100%"





                  <mx:HierarchicalData source="{dpHierarchy}"/>



                  <mx:AdvancedDataGridColumn headerText="" width="50"/>

                  <mx:AdvancedDataGridColumn dataField="Region"/>

                  <mx:AdvancedDataGridColumn dataField="Territory_Rep"

                      headerText="Territory Rep"/>

                  <mx:AdvancedDataGridColumn dataField="Actual"/>

                  <mx:AdvancedDataGridColumn dataField="Estimate"/>




        • 1. Re: Array collection
          Abhishek Chaudhary Level 1

          Providing hierarchical data in collection format is very simple.

          Dont make code complicated by creating a static array collection.

          You can display heirarchical collection in datagrid as follows:


          package <package name>


                    import mx.collections.ArrayCollection;

                    import mx.collections.ArrayList;


                    public class GridVO



                              public var id:Number;

                              public var name:String;

                              public var children:ArrayCollection = new ArrayCollection();





          Note: Your object must have name and children field, others are optional.


          children field is kept as Arraycollection of GridVOs.


          Assigining collection of these objects to DataGrid:

          lets say dp is our collection and input is heirarchical datatype

          var input:HierarchicalData;

          input=new HierarchicalData(dp);

          grid.dataProvider=input; // where grid is instance of datagrid.


          Please mark answer helpful or correct if your issue is resolved, you can get back in case of queries.




          Abhishek Chaudhary

          InfoCepts | www.infocepts.com