6 Replies Latest reply on Apr 28, 2008 2:48 PM by Dizzia

    Saving dynamic objects in a container to a dataGrid

    Dizzia
      I have an app which contains a dataGrid and a VBox container.

      dataGrid columns = username | objects

      VBox = holds children, objects (SWFLoaders)

      How would I be able to get the children back out of the dataGrid / save them to the dataGrid? Right now I'm using a VBox.getChildren(); and a dataGrid.selectedItem.objects = VBox.getChildren(); to get the information in. Is there any way to render it back out to the VBox so each user could have a different set of objects?

      Editing to show what the getChildren is returning - > AppName1.VBox.childName1,AppName1.VBox.childName2,AppName1.VBox.childName3, (etc)
      Any help, much appreciated.
        • 1. Re: Saving dynamic objects in a container to a dataGrid
          Dizzia Level 1
          Alright, so I still haven't figured this out. I'm playing around with saving / loading states. Anyone have any idea how to save out a dynamic state for just the VBox into the dataGrid, then call it back out in a load?

          • 2. Re: Saving dynamic objects in a container to a dataGrid
            peterent Level 2
            I'm a little confused by what you are trying to do. The DataGrid doesn't have any "children" like a VBox has children. Do you mean you are trying to display the data shown in a DataGrid in Flex component children of a VBox?

            This may not be at all what you are going for, but... If you have dataProvider on your DataGrid with the username objects, you can use that same dataProvider with a Repeater inside of a VBox:

            <mx:VBox>
            <mx:Repeater id="rep" dataProvider="{dp}">
            <mx:Label text="User name" /> <mx:TextInput text="{rep.currentItem.username}" />
            </mx:Repeater>
            </mx:VBox>

            So whatever is in the dataProvider, dp, when used with both a DataGrid and the Repeater, wil show up in both places.
            • 3. Re: Saving dynamic objects in a container to a dataGrid
              Dizzia Level 1
              peterent:

              Let me try to clarify.
              I'm using a VBox to visually display a series of graphics. I am getting those graphics into the VBox by adding them as children.
              I'm using a dataGrid to hold data about a user, and it is set up to hold multiple users. Each user has a series of data that is redisplayed when you select their index in the datagrid. This is all textual data, so I figured out how to get it to save into the datagrid without too much trouble. Also I figured out how to redisplay the selected data once it was out.
              (Every column in the datagrid is set to not be visible except for the name)

              The big problem I'm having is turning the children of the VBox into something that would a> save easily to the dataGrid and b> load easily back into the VBox. This way, in addition to the data that I already have for each user, I could also save a series of graphics, that I could load back in at a later time into the VBox.

              I kinda went down the roads of considering using states today. But I don't really know how to dynamically generate a state which would then save into a dataGrid, and then have that state work for many different end-users.

              So, I hope this cleared things up a little bit. If not, or if you think you might know what I'm sniffing at but aren't totally sure, I could show you my source / app.
              • 4. Re: Saving dynamic objects in a container to a dataGrid
                peterent Level 2
                I think the problem is some of your terminology - we to translate to ActionScript/Flex-speak. You said, "save easily to the DataGrid". What I think you mean is that you want to show these graphics that appear in the VBox now to appear in the DataGrid as well - is that correct?

                If that's the case, you can use a custom itemRenderer (I have series about itemRenderers on my blog - see my signature in this forum thread). The same code you use for the VBox you can use for the itemRenderer; you may need to do a little alteration but it will be basically the same thing.
                • 5. Re: Saving dynamic objects in a container to a dataGrid
                  Dizzia Level 1
                  Peterent:

                  Update your signature, macromedia pulled down their blogs!

                  Yeah, I think the terminology is a bit off. Let me try to fix that.

                  I used the repeater code in your last post, and that worked to display the objects in another VBox. Problem is, the datagrid won't accept objects. It just converts the getChildren() into Strings (I think).
                  So basically I have no way of saving the graphics in the VBox into the dataGrid (the datagrid is like temporary storage before I hit a database with the user data).

                  So, to wrap up. Repeaters are perfect for getting the data out of the dataGrid and back into the VBox. But I need a way to get the children that are in the VBox to go into the dataGrid. Right now they're dumping in as strings, which is no good. I need the nested data to go in with it.

                  The dataGrid is visible = false, so no worries about actually seeing the columns, it's there to hold an index for all of the users being created.

                  Thanks for all of the help
                  • 6. Re: Saving dynamic objects in a container to a dataGrid
                    Dizzia Level 1
                    Got it!

                    Okay, what I did was I extended the datagridcolumn component, and made a new one. One that was capable of accepting objects. Alright.