1

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?

1
  • What you can do is to generate DataGridColumn dynamically in ActionScript, rather then defining them in MXML milanl.blogspot.com/2009/06/… Commented May 20, 2011 at 20:31

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

I am using amfPHP .. I did try that ... i dropped all the objects and wrapped all the apples in an array .. but with no result. Also, my flex application is a desktop application (in case that matters). Just to see whats going on, I dropped all the nested arrays and used a plain simple one-dimensional array. Seems that also isnt getting displayed. I dont know what im doin wrong. the datafields labels etc e'thing ic correct. I even debugged and im getting the result on the flex side. whats going on ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.