8 Replies Latest reply on Feb 17, 2009 5:51 AM by alice_data

    Problem Populating and Creating a Dynamic DataGrid

    alice_data Level 1
      Hi,

      I have a scenario in the following and I am desperate that anyone reading this post could help me out. I have an array in the following that I would like to use its individual child element as the data of each column.

      I wonder if anyone can provide some pointers on how may I do this, since I cannot seem to populate the data, and therefore it keeps throwing the error of unable to create new column at me.

      Can anyone please help me out?

      Thanks in advance.

      Attached is the code.

      Alice
        • 1. Re: Problem Populating and Creating a Dynamic DataGrid
          alice_data Level 1
          Hi,

          After fiddling around with the code, I have edited my code what has been attached. However, the Alert.show boxes get populated correctly, and yet no new data column has been added.

          Looks like the result has been output correctly in the console with the trace function, but what I would like is to have it displayed on the DataGrid. Can anyone please give me a few pointers on this?

          Thanks in advance.
          • 2. Re: Problem Populating and Creating a Dynamic DataGrid
            Level 7

            "alice_data" <webforumsuser@macromedia.com> wrote in message
            news:gn3u3l$fe$1@forums.macromedia.com...
            > Hi,
            >
            > After fiddling around with the code, I have edited my code what has been
            > attached. However, the Alert.show boxes get populated correctly, and yet
            > no new
            > data column has been added.
            >
            > Looks like the result has been output correctly in the console with the
            > trace function, but what I would like is to have it displayed on the
            > DataGrid.
            > Can anyone please give me a few pointers on this?

            (1) You have two myDataGrid variables, one that's a DataGridColumn and is
            at the Application scope. Then you have one that is local to select_array()
            that is a DataGrid.
            (2) I don't see where you're actually adding a DataGrid to the Display
            List. Are you actually seeing a DataGrid anywhere on the screen?


            • 3. Re: Problem Populating and Creating a Dynamic DataGrid
              alice_data Level 1
              Hi, Amy:

              The answer to 2) is no. I don't see any DataGrid, and that is why I am starting to wonder if I am getting anything "built".

              As for 1), I am not sure if that is the way I am supposed to create a DataGrid by defining it like that from my cross reading on various forums and sites.

              Am I missing something here?
              Thanks for your help.

              Alice
              • 4. Problem Populating and Creating a Dynamic DataGrid
                alice_data Level 1
                Hi, Amy:

                Looks like when I add the line addChild(myDataGrid);at myDataGrid.dataProvider= selArr3; gives me a blank grid. :) I figured that this is because myDataGrid.dataProvider=selArr3 is initialized as empty, and therefore, keeps throwing me the error.

                What I am confused about is that I am trying to build the table dynamically by adding one column at a time, so I am supposed to start with a blank table with "no columns."

                Have I missed anything else here?

                Thanks for your help.

                Alice


                • 5. Re: Problem Populating and Creating a Dynamic DataGrid
                  Level 7

                  "alice_data" <webforumsuser@macromedia.com> wrote in message
                  news:gn473p$bhk$1@forums.macromedia.com...
                  > Hi, Amy:
                  >
                  > Looks like when I add the line addChild(myDataGrid);at
                  > myDataGrid.dataProvider= selArr3; gives me a blank grid. :)
                  >
                  > However, I found that while I am trying to create new columns from this
                  > same
                  > DataGrid based on what I have now, it gives me new blank DataGrid with no
                  > headers or data, instead of appending it to existing table.
                  >
                  > Have I missed anything else here?

                  What are you doing that constitutes "trying to create new columns from this
                  same DataGrid...?"


                  • 6. Re: Problem Populating and Creating a Dynamic DataGrid
                    alice_data Level 1
                    Hi, Amy:

                    What I mean is that I intend to create a DataGrid that contains all the columns I have specified in dg.columns = ["region_name", "population", "market"];

                    However, since all the values are generated dynamically, I could probably only add one column at a time, but I would like to add all the columns to one single dataGrid instead of creating a dataGrid for each of the columns. With my current code structure, I think I am creating something with individual columns on each of the new dataGrids.

                    Have I done something wrong to try to achieve what I wanted to do? With one DataGrid with multiple columns?

                    I hope this makes sense to what I am trying to do now.

                    Alice
                    • 7. Re: Problem Populating and Creating a Dynamic DataGrid
                      Level 7

                      "alice_data" <webforumsuser@macromedia.com> wrote in message
                      news:gn5fli$20d$1@forums.macromedia.com...
                      > Hi, Amy:
                      >
                      > What I mean is that I intend to create a DataGrid that contains all the
                      > columns I have specified in dg.columns = ["region_name", "population",
                      > "market"];

                      The DataGrid columns array needs to contain column objects, not strings.

                      > However, since all the values are generated dynamically, I could
                      > probably
                      > only add one column at a time, but I would like to add all the columns to
                      > one
                      > single dataGrid instead of creating a dataGrid for each of the columns.
                      > With my
                      > current code structure, I think I am creating something with individual
                      > columns
                      > on each of the new dataGrids.

                      Each object on the Display list can have only one parent. As the saying
                      goes, you can't have your cake and eat it, too. Or to put in a more
                      everyday metaphor, if you've loaned your red shoes to Martha, you can't also
                      wear them. So ifI'm understanding you correctly, you want to create one
                      datagrid with multiple columns, and then use those columns in several
                      datagrids? That's not possible.

                      > Have I done something wrong to try to achieve what I wanted to do? With
                      > one
                      > DataGrid with multiple columns?

                      It's completely possible to have multiple columns in a DataGrid. That's
                      what datagrids do. And obviously if your code isn't achieving what you set
                      out to do, there's a problem. It's just very difficult to tease out exactly
                      where your problem lies.

                      You may find this example helpful
                      http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-contr ol-in-flex/


                      • 8. Problem Populating and Creating a Dynamic DataGrid
                        alice_data Level 1
                        Hi, Amy:

                        Thanks for the heads up. I have seen that example before and went back to it, and fixed up the code that creates rreiterative DataGrid. It is finally working the way I wished it to be.

                        Alice