Highlighted

Populate data grid

senthilkumarvir

24-03-2009

hi i need to populate the data grid in mxml.

For that i need to call jsp from flex to get data.

Replies

Highlighted

Greg_Lafrance

25-03-2009

This code may help once you get your data back. It accesses a
data file but many of the principles are the same.



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"

creationComplete="dataRequest.send()">

<mx:Script>

<![CDATA[

import mx.events.ListEvent;

import mx.collections.XMLListCollection;

import mx.rpc.events.ResultEvent;



[Bindable] private var dataxlc:XMLListCollection = new
XMLListCollection();



private function resultHandler(e:ResultEvent):void {

var xmllist:XMLList = new XMLList(e.result..product);

dataxlc = new XMLListCollection(xmllist);

}

]]>

</mx:Script>

<mx:HTTPService id="dataRequest" useProxy="false"
resultFormat="e4x"

result="resultHandler(event)" url="data3.xml"/>

<mx:DataGrid dataProvider="{dataxlc}"
rowCount="{dataxlc.length}">

<mx:columns>

<mx:DataGridColumn dataField="@partnum"

headerText="Part Number"/>

<mx:DataGridColumn dataField="name"

headerText="Product Name"/>

</mx:columns>

</mx:DataGrid>

</mx:Application>

------------------------------- data3.xml
-----------------------------------

<?xml version="1.0" encoding="utf-8"?>

<products>

<product partnum="001">

<name>Desk</name>

</product>

<product partnum="002">

<name>Chair</name>

</product>

<product partnum="003">

<name>Table</name>

</product>

<product partnum="004">

<name>Bookshelf</name>

</product>

<product partnum="005">

<name>Lamp</name>

</product>

<product partnum="006">

<name>Computer</name>

</product>

<product partnum="007">

<name>Monitor</name>

</product>

</products>