1 Reply Latest reply on Mar 12, 2009 5:42 AM by SujitG

    DataGrid, multiple ArrayCollection data sources in same class?

    Rand1234
      I have a class defined like this:

      public class CategoryRecord
      {
      public var code : String;
      public var name : String;
      public var item1 : ArrayCollection;
      public var item2 : ArrayCollection;
      }

      Data gets loaded into item1 and item2 from a generic datasource, currently XML but will switch to some kind of RemoteObject or Web Services.

      After data is loaded, data looks like:

      item1[0]="red"
      item1[1]="white"
      item1[2]="green"
      item1[3]="brown"

      item2[0]="yes"
      item2[1]="no"
      item2[2]="no"
      item2[3]="yes"

      The data is related. item1[0] and item2[0] go together.

      What I want is to display them on a datagrid, in column format:

      red | yes
      white | no
      green | no
      brown | yes

      What I get is:

      red,white,green,brown | yes,no,no,yes

      The MXML:

      <mx:DataGrid id="Grid1"
      dataProvider="{categoryRecord}"
      selectedIndex="0">

      <mx:columns>
      <mx:DataGridColumn headerText="Color'"
      dataField="item1"/>

      <mx:DataGridColumn headerText="Required?"
      dataField="item2"/>
      </mx:columns>
      </mx:DataGrid>

      I tried using a labelFunction, but that didn't seem to help. It would hit the labelFunction 4 times, twice with no data, twice with data.

      I think part of the problem is I'm sending in a categoryRecord that is just 1 record, and it's confusing the Datagrid into thinking that I just want to print 1 line instead of 4. If I try feeding in "categoryRecord.item1", that works for item1 but not item2.

      Is there a way to feed in multiple data sources? Or a way to get it to show the ArrayCollections on the Datagrid as 4 rows instead of just 1 comma delimited row?

      Thanks for any help!
      Mike