2 Replies Latest reply on Jul 12, 2007 8:16 PM by hylim

    Passing data between datagridcolumn

    hylim
      Hi,

      I have the following data:

      class Item
      {
      public var name:String;
      public var infos: ArrayCollection;
      }

      class Info
      {
      public var id:String;

      }

      var items: ArrayCollection; //where items are arrays of Item


      I am creating a datagrid as follows:

      <mx:DataGrid id="dg" dataProvider="{items}" >
      <mx:columns>
      <DataGridColumn dataField="name" headerText="Name" />
      <DataGridColumn dataField="infos" headerText="Status" itemRenderer="{myRenderer}" />
      </mx:columns>
      </mx:DataGrid>

      in myRenderer.mxml:

      I need to access the name data from Item... but my dataField is {infos}

      In this case, how can I pass data from 1 column to another?

      Thank you very much.

      Regards,
      hy
        • 1. Re: Passing data between datagridcolumn
          ntsiii Level 3
          You do not need to set dataField for a colunmn with an item renderer. You will get a reference to the entire item object in the set data() function.

          Tracy
          • 2. Re: Passing data between datagridcolumn
            hylim Level 1
            Hi Tracy,

            Thank you for your reply.

            Just to confirm,
            in the function set data(value:Object) - this means I will get the reference to the Item class.

            I would like to ask for a more complicated case:

            Now my class is:

            class Item
            {
            public var name:String;
            }

            class Info
            {
            public var ids:ArrayCollection;

            }

            var items: ArrayCollection; //where items are arrays of Item
            var infos: ArrayCollection; //where infos are arrays of Info

            I have create a custom DataGridColumn component:
            class myDataGridColumn extends DataGridColumn
            {
            public var dataProvider: ArrayCollection;
            }

            In my datagrid, I dynamically add myDataGridColumn:

            <mx:DataGrid id="dg">
            <mx:columns>
            <myDataGridColumn dataProvider={items} headerText="Name" />
            <myDataGridColumn dataProvider={infos} headerText="Status" itemRenderer="{myRenderer}" />
            </mx:columns>
            </mx:DataGrid>


            in myRenderer.mxml:

            For each row, I need to access the name data from items; where the renderer will use the name to search through ids, before displaying the result.

            In this case, how can I pass data from 1 column to another, since the dataProvider for each column is different?

            Once again, thank you very much.

            Regards,
            hy