This content has been marked as final. Show 6 replies
Populate the DataGrid with an ArrayCollection e.g.
myDG.dataProvider = myArrCol;
Then later add the new row to myArrCol and then call the above line again.
You must set the dataProvider each time you change the underlying ArrayCollection.
Could you give me a example?
I found it in Help in define a new ArrayCollection or Array need to hardcode the column and value as follow:
var obj:Array =
I tried only use array to keep the value by index is fail to insert to datagrid. How can I implement it without hardcode column name?
The dataProvider will sort the key names into alphabetical order, so that in your case Account will end up as column 0 etc.
Put the columns in the order you want e.g. following will put Period first, then Account, then DC, then Amount:
var colarray:Array = new Array(myDG.columns, myDG.columns, myDG.columns, myDG.columns);
myDG.columns = colarray;
Now you can set the column headers:
colarray.headerText = "Period";
and so on.
This way the actual key names are not connected directly to the name in the column header.
If you set
var colname0:String = "Period";
colarray.headerText = colname0;
you can then change the value of the variable colname0 whenever you like and change the headerText whenever you like.
But how can I insert new row in this datagrid? Is create Object instance or Array instance? And how to define it and specify value?
As I said, you have to add the row to the ArrayCollection and then set the DataGrid's dataProvider equal to the new ArrayCollection.
If you use the ArrayCollection API (addItem, addItemAt), the DG *should* update, without requiring re-assignment of the dataProvider.