3 Replies Latest reply on Nov 19, 2008 5:34 AM by Newsgroup_User

    Dynamic AdvancedDataGridColumn filling

    dalejoel
      Hello -
      I did something and I want to see if others have done it this way or if there's a better way.

      I have an AdvancedDataGrid (ADG) with a series of columns that are generated at runtime. They each are used to represent the same type of data but for different objects. In my specific case.... each column represents an animal, and the row represents a particular measurement for that animal. The types of measurements are not known and how many animals are not known, until run time.

      Since the ADG hands off the dataProvider to each column for rendering and each column is expected to render some unknown number of measurements, I organized the row data into an array of dictionaries (each entry in the array being a single row) where the key is the name of the column, and the value is the measurement needed. Then, my single column renderer is common to all columns. It will access the dictionary by retrieving the name of the column that owns the renderer at that moment. The ADG just automatically hands off the correct dictionary corresponding to what row is being rendered, and the renderers always access with the same key (i.e. the column name). In this way I have created a data driven table with generic code.

      However... I know other people are making columns at runtime, and I'm wondering how anyone else may have organized their data so that dynamically generated columns have access to data that corresponds to that column. Is my method crazy cause it feels a bit complicated? All the ADG examples show accessing a different data field per column, and that just doesn't seem feasible in my scenario.

      Thank you,
      Joel
        • 1. Re: Dynamic AdvancedDataGridColumn filling
          thebouv Level 2
          I suppose another way to do it would be to loop through the data (eg: XML from an HTTPService) and dynamically add columns to an ADG with ActionScript. If the data had 3 columns, the ADG would have 3 columns. If the data had 4, the ADG would have 4. And so on.

          Seems like that would be a simpler method, but I haven't tried to hack out the code myself.
          • 2. Re: Dynamic AdvancedDataGridColumn filling
            ice9_us
            how you use the ADG will depend on how you want to display that data...
            using ADG or some other "TREE" type list is just as well.
            I use a httpservice that reads real time data pushed by ouside information..
            All real time.. dynamic type setup... i use the same thing your using..
            One problem i have found, which is hard to avoid.. is when the REAL time data updates..
            it resets your data grid and doesn't hold you were you are in your data grid.. i wish it wouldn't do that..
            • 3. Re: Dynamic AdvancedDataGridColumn filling
              Level 7

              "ice9_us" <webforumsuser@macromedia.com> wrote in message
              news:gg08ia$eke$1@forums.macromedia.com...
              > how you use the ADG will depend on how you want to display that data...
              > using ADG or some other "TREE" type list is just as well.
              > I use a httpservice that reads real time data pushed by ouside
              > information..
              > All real time.. dynamic type setup... i use the same thing your using..
              > One problem i have found, which is hard to avoid.. is when the REAL time
              > data
              > updates..
              > it resets your data grid and doesn't hold you were you are in your data
              > grid..
              > i wish it wouldn't do that..

              I think if your objects implement IUID, then Flex will see it as the same
              object. If you don't, Flex adds its own UID, and sees it as a different
              object.

              HTH;

              Amy