0 Replies Latest reply on Aug 11, 2010 5:13 AM by kiran@flex

    nested Arraycollection as a dataprovider to AdvancedDataGrid

    kiran@flex Level 1

      Hi ,

       

      Can we used nested Arraycollections as a dataprovider to AdvanceDataGrid.

       

      Consider the following Example

       

      InnerVO.as

       

      package

       

      {

       

       

      import mx.collections.ArrayCollection;

       

       

      public class InnerVO

      {

       

      public var dateRange:Number;

       

      public var dateRange2:Number;

      }

      }

       

       

      OuterVO.as

       

      package

      {

       

      import mx.collections.ArrayCollection;

       

       

      public class OuterVO

      {

       

      public var date:String;

       

      public var arrCOll:ArrayCollection;

      }

      }

       

      TestDB.as

       

      package

      {

       

      import flash.xml.XMLDocument;

       

      import flash.xml.XMLNode;

       

       

      import mx.collections.ArrayCollection;

       

      import mx.rpc.xml.SimpleXMLEncoder;

       

       

      public class TestDB

      {

       

      public var dp:ArrayCollection;

       

      public function TestDB()

      {

      dp =

      new ArrayCollection();

       

      var inVO1:InnerVO = new InnerVO();

      inVO1.dateRange = 11;

      inVO1.dateRange2 = 22;

       

       

      var inVO2:InnerVO = new InnerVO();

      inVO2.dateRange = 33;

      inVO2.dateRange2 = 44;

       

       

      var arrcoll:ArrayCollection = new ArrayCollection();

      arrcoll.addItem(inVO1);

      arrcoll.addItem(inVO2);

       

       

      var outVO1 :OuterVO = new OuterVO ();

      outVO1.date =

      "1/1/1";

      outVO1.arrCOll = arrcoll;

       

      dp.addItem(outVO1);

       

       

       

      var inVO4:InnerVO = new InnerVO();

      inVO4.dateRange = 55;

      inVO4.dateRange2 = 66;

       

       

      var inVO3:InnerVO = new InnerVO();

      inVO3.dateRange = 77;

      inVO3.dateRange2 = 88;

       

       

      var arrcoll1:ArrayCollection = new ArrayCollection();

      arrcoll1.addItem(inVO3);

      arrcoll1.addItem(inVO4);

       

       

      var outVO2 :OuterVO = new OuterVO ();

      outVO2.date =

      "1/1/1";

      outVO2.arrCOll = arrcoll1;

       

      dp.addItem(outVO2);

       

      }

      }

      }

       

      TestNestedADG.mxml (AIR Application)

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication

       

      xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="

      library://ns.adobe.com/flex/spark"

      xmlns:mx="

      library://ns.adobe.com/flex/mx"

      initialize="init()"

      >

       

      <fx:Declarations>

       

      <!-- Place non-visual elements (e.g., services, value objects) here -->

       

      </fx:Declarations>

       

      <fx:Script>

      <![CDATA[

       

      import mx.collections.ArrayCollection;

       

      public var test:TestDB = new TestDB();

       

      public var innervo1:InnerVO = InnerVO(OuterVO(test.dp[0]).arrCOll[0]);

      ]]>

       

      </fx:Script>

       

       

      <mx:AdvancedDataGrid id="adg" dataProvider="{test.dp}" height="100%" width="100%" >

       

      <mx:groupedColumns >

       

      <mx:AdvancedDataGridColumn dataField="date" headerText="Date" />

       

      <mx:AdvancedDataGridColumnGroup id="innerVO" headerText="innerVO" dataField="innervo1">

       

      <mx:AdvancedDataGridColumn id="col1" headerText="DateRange" dataField="dateRange"/>

       

      <mx:AdvancedDataGridColumn id="col2" headerText="DateRange2" dataField="dateRange2" />

       

      </mx:AdvancedDataGridColumnGroup>

       

      <mx:AdvancedDataGridColumnGroup id="innerVO1" headerText="innerVO" dataField="arrCOll">

       

      <mx:AdvancedDataGridColumnGroup headerText="12AM - 6AM">

       

      <mx:AdvancedDataGridColumn id="col3" headerText="DateRange" dataField="dateRange"/>

       

      <mx:AdvancedDataGridColumn id="col4" headerText="DateRange2" dataField="dateRange2"/>

       

      </mx:AdvancedDataGridColumnGroup>

       

      </mx:AdvancedDataGridColumnGroup>

       

      </mx:groupedColumns>

       

       

      </mx:AdvancedDataGrid>

      </s:WindowedApplication>

       

      It displays only the date field value of OuterVO,

      How to display all the fields inide the arrCOll in OuterVO.????

       

      - Also is it possible to create the multiple AdvancedDataGridColumGroups with diffrent columns at runtime???