Skip navigation
Currently Being Moderated

How to add Column to DataGrid?

Jan 30, 2010 1:29 PM

I have simple mxml code

 

<mx:DataGrid id="DGG"
            
editable="true">
   
<mx:dataProvider>
       
<fx:Object scheduledDate="4/1/2006"/>
   
</mx:dataProvider>
</mx:DataGrid>
<s:Button id="SetBut"
          
label="Set Array as Data Provider"
          
click="SetDP(); AddBut.visible = true;"
          
x="100.5"
          
y="164"
          
width="211"/>
<s:Button id="AddBut"
          
label="Add a column!"
          
click="AddCol();"
          
x="100.5"
          
y="194"
          
width="211"
          
visible="false"/>
<fx: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"));
    }
    ]]>
</fx:Script>

 

I want to add rows to my table datagrid.

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

So could you please tell me - how to add a row dynamically to dataGrid?

 
Replies
  • Currently Being Moderated
    Jan 30, 2010 2:54 PM   in reply to 7546445

    I think you need to reassign the columns property. (getting the columns property returns a copy of the array)

     

    Something like this:

     

    var columnArray:Array = DGG.columns;

    var newCol:DataGridColumn = new DataGridColumn("Umpire");

    columnArray.push(newCol);

    DCG.columns = columnArray;


     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points