3 Replies Latest reply on Aug 31, 2010 1:30 AM by Arun Lal

    How do I design a dynamically changing table in Flex 4?

    Blueplastic7

      So, I'm new to Flex 4 and have been doing the Flex in a Week crash course online.

       

      I need some help trying to build a dynamically growing or shrinking  table with columns and rows. The cell backgrounds of the table will  change color depending on an XML file.

       

      Sometimes a picture is worth a thousand words: http://drop.io/v0woo7w (password: flex)

       

      So, see that table at the top with green and blue and red squares?  What is the best approach to designing that? I'm thinking maybe the  AdvancedGrid control... is that the right way to go about it?

        • 1. Re: How do I design a dynamically changing table in Flex 4?
          Arun Lal
          //for adding columns to datagrid

          private function addDataGridColumn(dataField:String):void {
                          var dgc:DataGridColumn = new DataGridColumn(dataField);
                          var cols:Array = dataGrid.columns;
                          cols.push(dgc);
                          dataGrid.columns = cols;
          }

          //for removing columns
          private function removeDataGridColumn(dataField:String):void {
                         
                          var cols:Array = dataGrid.columns;
                          for(var i:int=0;i<cols.length;i++){
                               if(cols[i].datafield == "datafieldToBeRemoved"){
                                   cols.splice(i);
                               }
                          }
                          dataGrid.columns = cols;
          }


          Try these methods in your application to create a dynamic table.
          • 2. Re: How do I design a dynamically changing table in Flex 4?
            Blueplastic7 Level 1

            Hi Arun, thanks for the quick response!

             

            I will test this out tomorrow morning.

             

            So, do you think AdvancedGrid is the way for me to go or am I better off using loops and a bunch of label controls with a background color set?

             

            I was thinking a loop running every 5 seconds could autogenerate the table using some labels. The text field would be empty for the label, but the color could be set.

             

            Which approach do you think is better?

            • 3. Re: How do I design a dynamically changing table in Flex 4?
              Arun Lal Level 2

              Looking at your requirement, I think you should use AdvancedDatagrid. You can take the other approach as well but it will be very expensive wrt memory utilization.