4 Replies Latest reply on Feb 28, 2011 7:28 PM by emerson_rm

    Problem to create dynamic DataGrid with ItemRenderer

    emerson_rm

      Hi,

       

      I´ve been working in a project whose the purpose is create dynamic DataGrids.

       

      So, in runtime the keyuser fill in a form how many rows and columns he wants. After that, a function create a DataGrid (like a two dimensional arrays).

      The problem is:

       

      I need to use a Componente inside a DataGridColumn.

      So I use ItemRenderer, but, how I send a ArrayCollection value to the ItemRenderer?????

       

      Follow the code:

       

       

       

           /* Define rowcount based of total row number informed */
           dataGrid.rowCount = row;
      
           cols = new Array();
      
           for(i = 0; i <= col; i++){
                dgc = new DataGridColumn(i.toString());
                dgc.dataField = ("col_" + i);
      
                dgc.itemRenderer = new ClassFactory(MyComponent);
      
                cols.push(dgc);
           }
      
           dataGrid.columns = cols;
      
           /* Create the array with de values of the cells */
           arrayRubrica = new ArrayCollection();
      
           for(i = 0; i < row; i++){
                objeto = new Object();
      
                for(x = 0; x <= col; x++){
                     objeto["col_" + x] = "TEST-TEST-TEST";
                }
      
                arrayRubrica.addItem(objeto);
           }
      
      

       

      How I get the value of "col_x" inside Component of ItemRenderer????

       

      Let me know if you nedd any further info.

       

      Tks

        • 1. Re: Problem to create dynamic DataGrid with ItemRenderer
          Darrell Loverin Level 4

          Did you assign the ArrayCollection to the DataGrid's dataProvider property?

           

           

          -Darrell

          • 2. Re: Problem to create dynamic DataGrid with ItemRenderer
            emerson_rm Level 1

            Yes, the array is linked to the DataGrid.

             

            <mx:DataGrid id="dataGrid" dataProvider="{arrayRubrica}" width="100%" height="100%" />
            

             

            Any ideias?

            • 3. Re: Problem to create dynamic DataGrid with ItemRenderer
              Flex harUI Adobe Employee

              The entire object is the data property of the itemRenderer.

              • 4. Re: Problem to create dynamic DataGrid with ItemRenderer
                emerson_rm Level 1

                I got it!!!

                 

                I used the ClassFactory class to solve the issue.

                First, I created a ClassFactory instance, later I used the propertie properties to send a value of Index Control to ItemRenderer.

                 

                Inside the ItemRenderer, the value is manipulated with GET and SET and the main value was bindable in a Label component.

                 

                Here´s the code:

                 

                var i:int
                
                dgc = new DataGridColumn(i.toString());
                
                var dimensoesAvaliacaoCelulaItemRenderer:ClassFactory = new ClassFactory(dimensoesAvaliacaoCelula);
                dimensoesAvaliacaoCelulaItemRenderer.properties = { indiceCol:i };
                dgc.itemRenderer = dimensoesAvaliacaoCelulaItemRenderer;
                
                
                // The component <dimensoesAvaliacaoCelula>
                
                <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" paddingLeft="5" paddingRight="5">
                     <mx:Script>
                          <![CDATA[
                               [Bindable] private var _indiceCol:int = 0;
                
                               public function get indiceCol():int {
                                    return this._indiceCol;
                               }
                
                               public function set indiceCol(_indiceCol:int):void {
                                    this._indiceCol = _indiceCol;
                               }
                          ]]>
                     </mx:Script>
                     <mx:CheckBox id="dimensoesAvaliacaoCelulaCheckbox"/>
                     <mx:Label id="dimensoesAvaliacaoCelulaLabel" text="{data['col_' + _indiceCol]}"/>
                </mx:HBox>
                

                 

                Tks.

                 

                Emerson