4 Replies Latest reply on Dec 4, 2008 8:58 AM by nickname118

    datagrid in a datagrid

    nickname118
      Can someone help me in figuring out how to render a datagrid inside a datagrid?

      I have tried to create two datagrids datagrid1, and datagrid2. I set their dataproviders and columns.
      So they are functional as separate datagrids.

      Now I simply want another datagrid that has two columns, each of which contain one of the smaller datagrids.
      I set the dataprovider to an arraycollection containing the two datagrids,
      i.e. dataprovider[0] = {grid1: datagrid1, grid2: datagrid2};

      I set the data fields for the columns to grid1 and grid2 respectively.
      And I set the itemrenderer = new ClassFactory(DataGrid);

      Now, none of the data displays from the original datagrids. It just shows two columns with empty boxes.
      What have I done incorrectly, and what must I do to get this to work properly? I have seen a couple examples of this working before, but the code for these relies too much on mxml and static xml data for me to figure out how to translate it. I am trying to do this in just actionscript and I don't know where or what my data will be at run time, but probably will end up as an arraycollection of some sort.
        • 1. Re: datagrid in a datagrid
          Level 7

          "nickname118" <webforumsuser@macromedia.com> wrote in message
          news:gh6doc$eig$1@forums.macromedia.com...
          > Can someone help me in figuring out how to render a datagrid inside a
          > datagrid?
          >
          > I have tried to create two datagrids datagrid1, and datagrid2. I set their
          > dataproviders and columns.
          > So they are functional as separate datagrids.
          >
          > Now I simply want another datagrid that has two columns, each of which
          > contain
          > one of the smaller datagrids.
          > I set the dataprovider to an arraycollection containing the two datagrids,
          > i.e. dataprovider[0] = {grid1: datagrid1, grid2: datagrid2};
          >
          > I set the data fields for the columns to grid1 and grid2 respectively.
          > And I set the itemrenderer = new ClassFactory(DataGrid);
          >
          > Now, none of the data displays from the original datagrids. It just shows
          > two
          > columns with empty boxes.
          > What have I done incorrectly, and what must I do to get this to work
          > properly?
          > I have seen a couple examples of this working before, but the code for
          > these
          > relies too much on mxml and static xml data for me to figure out how to
          > translate it. I am trying to do this in just actionscript and I don't know
          > where or what my data will be at run time, but probably will end up as an
          > arraycollection of some sort.

          How are you setting the dataproviders on the inner datagrids, and is there
          information at that level of the structure to feed them?


          • 2. Re: datagrid in a datagrid
            nickname118 Level 1
            OK, I have two dataproviders for the inner grids. Just two array collections, I don't need to go into what the data is. Let's say they are just strings or numbers for now.

            var dataprovider1:ArrayCollection = new ArrayCollection(
            [{ data: 1, data2: 2, etc..}]);
            var dataprovider2:ArrayCollection = new ArrayCollection(
            [{ data: 3, data2: 4, etc..}]);

            var grid1:DataGrid = new DataGrid();
            grid1.dataProvider = dataprovider1;

            var grid2:DataGrid = new DataGrid();
            grid2.dataProvider = dataprovider2;


            var outerDataProvider:ArrayCollection = new ArrayCollection(
            [{grid1: grid1, grid2:grid2}]);

            var outterGrid:DataGrid = new DataGrid();
            outterGrid.dataProvider = outerDataProvider;


            I'm not sure what you mean by "information at that level of the structure to feed them". I have assigned the data providers, and they have data in them... So what do you mean?

            I left out the code, but for the collumns I reference the appropriate names from each arraycollection in the dataproviders. And for the outterGrid I assign an itemrenderer of type DataGrid. I do this specifically with a ClassFactory, because the itemrenderer field is an IFactory object.
            • 3. Re: datagrid in a datagrid
              Level 7

              "nickname118" <webforumsuser@macromedia.com> wrote in message
              news:gh6k5p$m8o$1@forums.macromedia.com...
              > OK, I have two dataproviders for the inner grids. Just two array
              > collections, I
              > don't need to go into what the data is. Let's say they are just strings or
              > numbers for now.
              >
              > var dataprovider1:ArrayCollection = new ArrayCollection(
              > [{ data: 1, data2: 2, etc..}]);
              > var dataprovider2:ArrayCollection = new ArrayCollection(
              > [{ data: 3, data2: 4, etc..}]);
              >
              > var grid1:DataGrid = new DataGrid();
              > grid1.dataProvider = dataprovider1;
              >
              > var grid2:DataGrid = new DataGrid();
              > grid2.dataProvider = dataprovider2;
              >
              >
              > var outerDataProvider:ArrayCollection = new ArrayCollection(
              > [{grid1: grid1, grid2:grid2}]);
              >
              > var outterGrid:DataGrid = new DataGrid();
              > outterGrid.dataProvider = outerDataProvider;
              >
              >
              > I'm not sure what you mean by "information at that level of the structure
              > to
              > feed them". I have assigned the data providers, and they have data in
              > them...
              > So what do you mean?

              Typically, an itemrenderer is, well, rendering an item. So if you have a
              need for a datagrid as an itemRenderer, that item should contain data that
              could serve as a dataProvider itself. This would be the case if, for
              instance, you had a nested ArrayCollection (HierarchicalData), or if you had
              hierarchical XML.

              > I left out the code, but for the collumns I reference the appropriate
              > names
              > from each arraycollection in the dataproviders.

              That doesn't even make any sense. To make thiswork, you're almost certainly
              going to have to make a custom itemRenderer. I don't think there's any way
              to specify a dataProvider for something _inside_ an itemRenderer from the
              column definition.

              > And for the outterGrid I assign
              > an itemrenderer of type DataGrid. I do this specifically with a
              > ClassFactory,
              > because the itemrenderer field is an IFactory object.

              I understand all the words you used, but they don't come together into any
              sort of sensible whole.



              • 4. Re: datagrid in a datagrid
                nickname118 Level 1
                I'm sorry, but I think you just bypassed my question and the code I posted.

                I am talking as an object-programmer. I am not typically a Flex programmer, but I am forced to do things in Flex due to a team design decision. If you don't understand what I am talking about when referring to my code, that would probably be the source of the confusion.

                Anyway. I don't know the underworkings of a DataGrid class and how it uses DataGridColumns. But I had tried to instantiate everything through actionscript and assign values that way.

                I defined some DataGridColumns in this way.

                var column1:DataGridColumn = new DataGridColumn();
                column1.dataField = "grid1";
                column1.itemrenderer = new ClassFactory(DataGrid);

                var column2:DataGridColumn = new DataGridColumn();
                column2.dataField = "grid2";
                column2.itemrenderer = new ClassFactory(DataGrid);

                This works. The only issue is that no data or any information whatsoever from the DataGrid oject contained within the outterGrid's dataProvider is getting loaded. What I described is precisely a nested ArrayCollection.

                Like I said the outterGrid has arrayCollection with objects [{grid1: grid1, grid2: grid2}, {grid1: someotherGrid, grid2: someotherGrid2}]

                Then there are separate dataProviders within the grid1 and grid2 DataGrids. I don't understand why the outterGrid ever needs to see or know about the dataProviders contained in the inner grids. If the innerGrid knows how to render itself outside of the outterGrid, then why can it not render within the outterGrid? Clearly the outterGrid is not calling some generic renderering function on its inner components, and it is causing me much frustration.