6 Replies Latest reply on May 23, 2011 11:00 PM by linrsvp

    Nested Objects for a Data Provider in a Data Grid, not displaying data

    linrsvp Level 1

      Hi, 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 ??? Please help!! 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.

      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. Even in this case the data
      isnt getting displayed.
      I dont know what im doin wrong. the datafields, labels etc e'thing is correct. I even debugged and
      im getting the result on the flex side. whats going on ?

        • 1. Re: Nested Objects for a Data Provider in a Data Grid, not displaying data
          Flex harUI Adobe Employee

          You will need to convert the data to a list.

          • 2. Re: Nested Objects for a Data Provider in a Data Grid, not displaying data
            linrsvp Level 1

            No luck ... i converted the result set to a List, and even tried with an iList. Same problem -  nothing gets displayed...

             

            I have no idea whats happening ....


            This is my code :

             

            [Bindable]private var privilegesArray:ArrayCollection = new ArrayCollection();

             

            public function init():void{ // called on creation complete
                            RO.getPrivileges.addEventListener(ResultEvent.RESULT,handleGetPrivileges);
                            RO.getPrivileges();
                        }

             

            protected function handleGetPrivileges(event:ResultEvent):void{
                            privilegesArray = event.result as ArrayCollection;
                        }

             

            <mx:DataGrid id="privilegesDG" dataProvider="{privilegesArray}" width="100%">
                    <mx:columns>
                        <mx:DataGridColumn headerText="Name" dataField="name" />
                        <mx:DataGridColumn headerText="Alias" dataField="alias" />
                    </mx:columns>
                </mx:DataGrid>

             

            The data that gets returned is smthing like this : (for the moment I have removed all the nested objects and arrays and returning just a simple plain array)

            Array => [0] => Object #1

                                      [name] => some name

                                      [alias] => alias

            • 3. Re: Nested Objects for a Data Provider in a Data Grid, not displaying data
              FlexSpring

              canyou please try on item renderer like following

               

              <?xml version="1.0" encoding="utf-8"?>

              <mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark"

              xmlns:mx="library://ns.adobe.com/flex/mx"

              >

               

               

              // in ur case number of lable sould be dynamic.

              there should be a for each loop for data.three    { according to [three] => Object #2      }

               

               

              <fx:Script>

              <![CDATA[

              for each(var temp:Object in data.object2)

              {

              var lbl:Label=new Label();

              ....

              ...

              ..

              .

               

              }

              ]]>

              </fx:Script>

               

               

              </mx:VBox>

              • 4. Re: Nested Objects for a Data Provider in a Data Grid, not displaying data
                linrsvp Level 1

                hi,

                that might work.. but i just realised that my privilegesArray isnt geting populated at all!!! I tried something like this :

                 

                 

                protected function handleGetPrivileges(event:ResultEvent):void{
                                privilegesArray = event.result as ArrayCollection;
                                if(privilegesArray == null)
                                    Alert.show("array not populated");
                            }

                 

                And the alert showed .. when i debugged, i can see the result in the events.result object... but for some reason the privilegesArray isnt getting populated... This is even weird ... any ideas ?

                • 5. Re: Nested Objects for a Data Provider in a Data Grid, not displaying data
                  linrsvp Level 1

                  ok i got it to work.. but im still confused ...

                   

                  I made the privilegesArray an object (instead of an arraycollection/list/ilist).. and voila! it worked like a charm ...

                   

                  apparently, something is ging wrong here :

                   

                  privilegesArray = event.result as ArrayCollection;

                   

                  any idea why ?

                   

                  so now i just changed it to :

                   

                  privilegesArray = event.result (since result is an object)

                   

                  and it worked!! .. now im gonna introduce the nesting and see if that itemrenderer solution works ...

                   

                  im sure i'l be back here very soon.. wish me luck!

                  • 6. Re: Nested Objects for a Data Provider in a Data Grid, not displaying data
                    linrsvp Level 1

                    the itemrenderer solution does work ... my data gets displayed now ... but my datagrid acts real funny when it gets refreshed ...

                     

                    gonna post that in another thread .. thanks for all the help!