1
votes

I have a datagrid and the dataprovider for this grid is the result of a RPC call. The result set has the following structure:

Array
[0]->Object #1
      [one] => 1
      [two] => 1
      [three] => Object #2
          [apple1] = > Object #3
              [color] =>    red
              [rate] => 20
          [apple2] => Object #4 ( the    number of apples is dynamic, apple3,apple4 .. and so on)
              [color] =>    blue
              [rate] => 100

and so on ... so the number of apple objects will vary since its dynamic. How do I display this data in a datagrid?

I saw many articles on creating the "Nested DataGridColumn " classes... like this :

http://active.tutsplus.com/tutorials/flex/working-with-the-flex-datagrid-and-nested-data-structures/

It helps, but the problem with my data is that some of the indexes (like apple1,apple2 etc.) are dynamic. How do I include those?

2
What you can do is to generate DataGridColumn dynamically in ActionScript, rather then defining them in MXML milanl.blogspot.com/2009/06/…JabbyPanda

2 Answers

1
votes

I got this working.

I used an inline item renderer and used a foreach loop to loop through the object containing the dynamic nested objects within. This is my code :

<mx:DataGridColumn headerText="Roles Assigned">
<mx:itemRenderer>
<fx:Component>
    <mx:VBox creationComplete="box1_creationCompleteHandler()">
    <fx:Script>
    <![CDATA[
        import com.pm.modules.events.UpdateDBEvent;     
        import mx.containers.HBox;
        import mx.controls.Alert;
        import mx.controls.Label;
        import mx.controls.LinkButton;
        import mx.events.FlexEvent;     

        protected function box1_creationCompleteHandler():void
        {
        for each(var temp:Object in data.roles){
            var hgrp:HBox = new HBox();
            hgrp.autoLayout = false;
            var lbl:Label = new Label();
            lbl.text = temp.rname;
            var lb:LinkButton = new LinkButton();
            lb.label = 'X';
            lb.id = temp.rid.toString();
            lb.focusEnabled = true;
            lb.addEventListener(MouseEvent.CLICK,handleClick);

            hgrp.addElement(lbl);
            hgrp.addElement(lb);
            this.addElement(hgrp);
        }
    }

    protected function handleClick(event:MouseEvent):void{
      dispatchEvent(new UpdateDBEvent(UpdateDBEvent.ON_DELETE_PRIVILEGE_ROLE_MAP,0,0,0,event.target.id,0,true));
    }
]]>
</fx:Script>
</mx:VBox>
</fx:Component></mx:itemRenderer></mx:DataGridColumn>
0
votes

What server side technology are you using? BlazeDs / amfphp, something else?

What you should do is wrap your apples in an ArrayCollection and then you should be fine.

[0]->RPC Result
 [one] => 1
 [two] => 1
 [three] => ArrayCollection
     [1] = > Apple#3
          [color] => red
          [rate] => 20
     [2] => Apple #4 ( the number of apples is dynamic, apple3,apple4 .. and so on)
          [color] => blue
          [rate] => 100