Sunday, October 18, 2009

Flex (Basic Tutorial) a quick way to display data to Datagrid

Im trying abit of Adobe Flex, and found it so far good for
- loading data direct to client side(user can do real time sorting without re-loading the page/data)
- good for loading images and videos
- good for drawing i suppose.

Adobe website has a tutorial for loading data to datagrid via amazon, rss feed. Saw a blog that you can also load data via any xml file via the same 'mx:HTTPservice'

Below are the sample code:-


'datafeed.asp'
<users>
<student>
<name>Jamal</name>
<email>Jamal@flex.com</email>
</student>

<student>
<name>Janna</name>
<email>Janna@flex.com</email>
</student>

<student>
<name>surifir</name>
<email>surifir@flex.com</email>
</student>

<student>
<name>ibrahim</name>
<email>ibrahim@flex.com</email>
</student>
</users>



FeedReader.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="rssRequest.send()">

<mx:HTTPService
id="rssRequest"
url="http://localhost/flexrss/dataFeed.asp" />

<mx:VBox width="100%" height="100%">
<mx:DataGrid width="643" dataProvider="{rssRequest.lastResult.users.student}">
<mx:columns>
<mx:DataGridColumn headerText="name" dataField="name"/>
<mx:DataGridColumn headerText="email" dataField="email"/>

</mx:columns>
</mx:DataGrid>
</mx:VBox>

</mx:Application>



That about it, more of less if this is useful, im happy it helps, else this is really more of a code sample reference for ..heh! ME.




Once more thing i was trying to do today but forgot was this:-


<mx:DataGrid id="dg" width="100%" dataProvider="{rssRequest.lastResult.Messages.Message}"
click="{txta_msg.htmlText=rssRequest.lastResult.Messages.Message[dg.selectedIndex].body}"
>
<mx:columns>
<mx:DataGridColumn headerText="From" dataField="sender_name"/>
<mx:DataGridColumn headerText="Subject" dataField="subject"/>
<mx:DataGridColumn headerText="Date" dataField="createdate"/>
</mx:columns>
</mx:DataGrid>
<mx:TextArea width="100%" height="272" id="txta_msg" editable="false" wordWrap="true" borderStyle="solid" borderThickness="6" cornerRadius="6" alpha="1.0" backgroundColor="#FAE068" backgroundAlpha="1.0" paddingBottom="4" paddingLeft="4" paddingRight="4" paddingTop="4"/>



What is does, when i click on the datagrid record, the body message is loaded to the text area, simple and easy, yet i cant recall how to do it initially!

No comments: