Flex News , Links & Resources

Binding DataGrid to HTTPService in Flex 3 : http://www.manfridayconsulting.it/

Posted by: arunbluebrain on: January 27, 2009

How to consume an HTTPService using Xml Object. You can see the power of Databinding in this environment.
You only need to set the property dataProvider=”{productsarray}” of the DataGrid to get all objects coming from
on results function.
Here an example of Xml object definition
<dataroot>
<product>
<id>1</id>
<total>2</total>
<name>Motherboard</name>
<price>100</price>
</product>
<product>
<id>2</id>
<total>2</total>
<name>Pprocessor</name>
<price>150</price>
</product>
</dataroot>
Now we start with the sample application:
<mx:Application
xmlns:mx=”http://www.adobe.com/2006/mxml
layout=”absolute
creationComplete=”initApp()“>
<mx:HTTPService id=”srv” url=”services/products.xml
resultFormat=”object
result=”onResult(event)“/>
<mx:  DataGrid id=”grid
width=”100%
height=”100%
dataProvider=”{productsarray}“>
<mx:columns>
<mx:  DataGridColumn headerText=”Total No.”
dataField=”total“/>
<mx:  DataGridColumn headerText=”Name
dataField=”name“/>
<mx:  DataGridColumn headerText=”Price
dataField=”price“/>
</mx:columns>
</mx:  DataGrid>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var productsarray:ArrayCollection;
private function initApp():void {
this.srv.send();
}
private function onResult(evt:ResultEvent):void {
this.productsarray = evt.result.data.product;
}
]]>
</mx:Script>
</mx:Application>

2 Responses to "Binding DataGrid to HTTPService in Flex 3 : http://www.manfridayconsulting.it/"

Off-topic, but I’m curious how you color coded the mxml/actionscript code samples?

fine with this example; now, how do you refresh the grid if a change occurs in the XML? can you place a “refresh” button and show me how to do this? thanks

Leave a Reply

Categories

Blog Visitor Clicks

  • 76,150 hits

See by Date

January 2009
M T W T F S S
« Dec   Feb »
 1234
567891011
12131415161718
19202122232425
262728293031  

Flex Hackr

Im tweeting

my Delicious Links