Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
McDusty #1
ArrayCollection to populate Datagrid
Hi,
Im having problems getting my own array data to bind to a dataGrid. I've tried
formating my array data several ways but none work. Here is an example of one
of the iterations i have tried which i beleive should work. I build my array
like this ...
for(i) {
arrayName.push( [{ fieldName1: value<i> , fieldName2: value<i>}] );
}
which gives me a nice 2d array. this is put in an arrayCollection which is
bindable....
arrayCol = new ArrayCollection( arrayName);
and it is set as the dataProvider for my grid and the fieldNames are set as
the column dataFields ...
<mx:DataGrid x="424" y="425" height="125" width="340" id="grd" editable="true"
enabled="true" dataProvider="{arrayCol}">
<mx:columns>
<mx:DataGridColumn headerText="Tag" dataField="fieldName1"
editable="false"/>
<mx:DataGridColumn headerText="Tag Value" dataField="fieldName1"
editable="true"/>
</mx:columns>
</mx:DataGrid>
I've spent a fair time trying to work this out and search the docs / this
forum. If anyone has any recommendations about how to bind array /
arrayCollection data to a dataGrid it would be greatly appreciated.
Regards
McDusty Guest
-
How to populate Advanced DataGrid
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <mx:Script> <! public var... -
populate textInput from DataGrid
Please help! My DataGrid has "FIELD_NAME" and "FIELD_VALUES" columns. My TextInput objects has to match id names from "FIELD_NAME" columns, and... -
Populate Datagrid from Client side
Hi All, I have a parent page. It will pop up a modal dialog (by calling show modal dialog) window. Dialog window will return a long string which... -
Datagrid doesnt populate :(
Hello Im trying to do a simple page with data from my local sql server, and page just shows up blank...... I created a stored procedure with... -
How can I select items in a datagrid to populate a second datagrid.
I currently have a datagrid that looks like the following. Sales Table Date Dogs Cats Fish 5/1/2004 4 ... -
Mike Morearty (Adobe) #2
Re: ArrayCollection to populate Datagrid
The way you have it structured, it looks like you have a two-dimensional array
where the second dimension always just contains a single item. Unless I'm
misinterpreting your goal, the way to change this would be to remove the extra
left/right brackets in your arrayName.push:
change
arrayName.push( [{ fieldName1: value<i> , fieldName2: value<i>}] );
to
arrayName.push( { fieldName1: value<i> , fieldName2: value<i>} );
That way, you have a one-dimensional array, but each item in that array has a
field named 'fieldName1' and another field named 'fieldName2'.
Here is a complete sample that works for me (with the latest internal build --
I haven't tried beta 3):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="initData()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
public var mydata:Array;
[Bindable]
public var arrayCol:ArrayCollection;
private function initData():void
{
mydata = [];
mydata.push( { fieldName1: '1', fieldName2: '2' } );
mydata.push( { fieldName1: '3', fieldName2: '4' } );
arrayCol = new ArrayCollection(mydata);
}
]]>
</mx:Script>
<mx:DataGrid x="424" y="425" height="125" width="340" id="grd" editable="true"
enabled="true" dataProvider="{arrayCol}">
<mx:columns>
<mx:DataGridColumn headerText="Tag" dataField="fieldName1" editable="false"/>
<mx:DataGridColumn headerText="Tag Value" dataField="fieldName2"
editable="true"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
--
Mike Morearty
Developer, Flex Builder team
[url]http://www.morearty.com/blog[/url]
McDusty wrote:> Hi,
>
> Im having problems getting my own array data to bind to a dataGrid. I've tried
> formating my array data several ways but none work. Here is an example of one
> of the iterations i have tried which i beleive should work. I build my array
> like this ...
>
> for(i) {
> arrayName.push( [{ fieldName1: value<i> , fieldName2: value<i>}] );
> }
>
> which gives me a nice 2d array. this is put in an arrayCollection which is
> bindable....
>
> arrayCol = new ArrayCollection( arrayName);
>
> and it is set as the dataProvider for my grid and the fieldNames are set as
> the column dataFields ...
>
> <mx:DataGrid x="424" y="425" height="125" width="340" id="grd" editable="true"
> enabled="true" dataProvider="{arrayCol}">
> <mx:columns>
> <mx:DataGridColumn headerText="Tag" dataField="fieldName1"
> editable="false"/>
> <mx:DataGridColumn headerText="Tag Value" dataField="fieldName1"
> editable="true"/>
> </mx:columns>
> </mx:DataGrid>
>
> I've spent a fair time trying to work this out and search the docs / this
> forum. If anyone has any recommendations about how to bind array /
> arrayCollection data to a dataGrid it would be greatly appreciated.
>
> Regards
>Mike Morearty (Adobe) Guest
-
McDusty #3
Re: ArrayCollection to populate Datagrid
cheers for your response Mike.
It works a treat!
McDusty Guest



Reply With Quote

