1 Reply Latest reply on Jan 31, 2010 4:28 AM by archemedia

    How to add Column to Adobe flex mx:DataGrid in mxml and/or actionsctpt?

    7546445 Level 1

      I have simple mxml code

       

       

      <mx:DataGrid id="DGG"
                  
      editable="true">
         
      <mx:dataProvider>
             
      <mx:Object scheduledDate="4/1/2006"/>
         
      </mx:dataProvider>
      </mx:DataGrid>
      <mx:Button id="SetBut"
                
      label="Set Array as Data Provider"
                
      click="SetDP(); AddBut.visible = true;"
                
      x="100.5"
                
      y="164"
                
      width="211"/>
      <mx:Button id="AddBut"
                
      label="Add a column!"
                
      click="AddCol();"
                
      x="100.5"
                
      y="194"
                
      width="211"
                
      visible="false"/>
      <mx:Script>
          <![CDATA[
              import mx.controls.dataGridClasses.DataGridColumn;
              import mx.collections.ArrayCollection;

              [Bindable]
              public var MyAC:ArrayCollection=new ArrayCollection([{scheduledDate: "4/1/2006", homeTeam: "Chester Bucks"}]);

              public function SetDP():void
              {
                  DGG.dataProvider=MyAC
              }

              public function AddCol():void
              {
                  MyAC.addItem({scheduledDate: "4/5/2007", homeTeam: "Long Valley Hitters", Umpire: "Amanda Hugenkis"});
                  DGG.columns.push(new DataGridColumn("Umpire"));
              }
          ]]>
      </mx:Script>

      I want to add rows to my table datagrid how to do such thing?

      How to add Column to Adobe flex mx:DataGrid in mxml and/or actionsctpt?

      (You can put this code in Flash or AIR app - it will compile with no errors, but will not add any columns=( )

        • 1. Re: How to add Column to Adobe flex mx:DataGrid in mxml and/or actionsctpt?
          archemedia Level 4

          Change this:

           

                       public function SetDP():void
                      {
                          DGG.dataProvider=MyAC
                          MyAC.addItem({scheduledDate: "4/5/2007", homeTeam: "Long Valley Hitters", Umpire: "Amanda Hugenkis"});
                      }
                     
                      public function AddCol():void
                      {
                          var dgc:DataGridColumn = new DataGridColumn("Umpire");
                          var ca:Array = DGG.columns;
                          ca.push(dgc);
                          DGG.columns = ca;
                      }

           

          Dany