4 Replies Latest reply on Jan 22, 2010 2:35 AM by ForestDemon

    Need to access an ArrayCollection within an ArrayCollection for dataField in DataGrid.

    ForestDemon

      I have a DataGrid and the DataProvider is an ArrayCollection; however, some of my dataFields need to access data from an ArrayCollection within the DataProvider's ArrayCollection.

       

      How can I access the "embedded" ArrayCollection to populate the dataFields?

       

      Thanks...

        • 1. Re: Need to access an ArrayCollection within an ArrayCollection for dataField in DataGrid.
          Sebastien V. Level 3

          You can use a labelFunction for the dataGrid's column and do whatever you need to do in it.

          • 2. Re: Need to access an ArrayCollection within an ArrayCollection for dataField in DataGrid.
            niranjan swain Level 1

            hi,

            there is two way for acess it but before that we should know about the datastructure of dataprovider.

            if u create the dataprovider dynamically or add object with in object the u retrive corresponding child. it is better if give the sample data.

             

            Thanks

            Niranjan

            • 3. Re: Need to access an ArrayCollection within an ArrayCollection for dataField in DataGrid.
              archemedia Level 4

              The problem is that in a dataGrid, you can set the dataField property but is this is an object, it won't work.

               

              The solution is to override the data property in your itemRenderer. You can then do whatever you want, like examining if there's another ArrayCollection in your data property:

               

              Here's an abstract example:

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
                  <mx:Script>
                      <![CDATA[
                          import mx.collections.ArrayCollection;
                         
                          [Bindable]
                          private var dp:ArrayCollection;
                         
                          private function init():void
                          {
                              var arr:Array = [{v1: 1, v2: 2, v3: ["one", "two", "three"]},
                                                  {v1: 3, v2: 4, v3: ["four", "five", ["six", "seven"]]}];
                              dp = new ArrayCollection();
                              dp.source = arr;
                          }
                         
                      ]]>
                  </mx:Script>
                  <mx:DataGrid id="dg" width="100%" height="100%" dataProvider="{dp}">
                      <mx:columns>
                          <mx:DataGridColumn headerText="C1" dataField="v1"/>
                          <mx:DataGridColumn headerText="Value 1">
                              <mx:itemRenderer>
                                  <mx:Component>
                                      <mx:HBox>
                                          <mx:Script>
                                              <![CDATA[
                                                  override public function set data(value:Object):void
                                                  {
                                                      var d:Object = value.v3[2];
                                                      if (d is Array)
                                                      {
                                                          super.data = d[0]
                                                      } else
                                                      {
                                                          super.data = d;
                                                      }
                                                  }
                                              ]]>
                                          </mx:Script>
                                          <mx:Label text="{data}"/>
                                      </mx:HBox>
                                  </mx:Component>
                              </mx:itemRenderer>
                          </mx:DataGridColumn>
                      </mx:columns>
                  </mx:DataGrid>
                 
              </mx:Application>

               

               

              Dany

              • 4. Re: Need to access an ArrayCollection within an ArrayCollection for dataField in DataGrid.
                ForestDemon Level 1

                >You can use a labelFunction for the dataGrid's column and do whatever you need to do in it.

                 

                I researched this and hacked for a while.  Everything is working as expected and with very little code.

                 

                Thanks for your input...