Flex Datagrid to Array

apache-flexarrays

I need to convert a datagrid table in Adobe Flex to an ArrayCollection. I was expecting to be able to loop through each row of a datagrid and write that to the Array collection, but the only method for accessing data in the datagrid that I can find is SelectedItem, which doesn't help me.

Obviously one could just copy the dataProvider for the datagrid, but my datagrid is editable and I need to store the state of the datagrid at any one time into a database. Can anyone recommend a method of doing this?

Much Appreciated

-Matt

Best Answer

If your DataGrid is:

<mx:DataGrid id="someDG" dataProvider="{this.provider}" />

Then check if this.provider is Array or ArrayCollection. If it is ArrayCollection then access it simply by:

var gotIt:ArrayCollection = this.someDG.dataProvider as ArrayCollection;

if it is an Array, then:

var gotIt:ArrayCollection = new ArrayCollection(this.someDG.dataProvider as Array);

Hope this helps.