Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-12-2008, 06:23 PM   #1
tdurant
Registered User
 
Join Date: May 2008
Posts: 4
Unhappy datagrid

I am new to flex so forgive me.

I am trying to do something I thought was simple, import an xml into a datagrid then allow for searching of items, then the user can click on searched item to launch a pdf. I have been working for days on this and am going crazy. help

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

<mx:HTTPService id="srv" url="data/courses.xml"/>
<mxataGrid id="dg" dataProvider="{srv.lastResult.courseData.courseInf o}" width="518" height="210"/>
</mx:Application>

xml example

<courseData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<courseInfo>
<courseNumber>17533-01f</courseNumber>
<courseName>Operation Skills: Facility Operating Plan</courseName>
<courseURL>http://link/17533-01.pdf</courseURL>
</courseInfo>
</courseData>

by the way im using flex 2.1
tdurant is offline   Reply With Quote
Old 05-14-2008, 06:11 PM   #2
tdurant
Registered User
 
Join Date: May 2008
Posts: 4
Default help still working on it

I have be at least partially sucessful. I was able to add a link to the datagrid, kinda, by populating a button using the selected item, but I still can get a search or filter to work. help!!!

mxml code

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

<mx:Script>
<![CDATA[
import mx.controls.Button;

import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.collections.IViewCursor;
import mx.controls.Alert;

[Bindable]
private var selectedItem:Object;

[Binable]
private var srv:ArrayCollection = new ArrayCollection;

private function resultHandler(event:ResultEvent):void{
mySrv = event.result.courseData.courseInfo;
dg.selectedIndex=0;
}

public function filter():void{
srv.filterFunction = filterFirst;
srv.refresh();
}

private function filterFirst(item:Object):Boolean{
return (item.first == searchField.text)
}
]]>
</mx:Script>
<mx:HTTPService id="mySrv" url="data/courses.xml"/>

<mx:Form width="549">
<mx:FormItem label="Search" direction="horizontal" width="510">
<mx:TextInput id="searchField" change="srv.refresh()" />

</mx:FormItem>
</mx:Form>
<mxataGrid id="dg" dataProvider="{mySrv.lastResult.courseData.courseI nfo}" width="606"/>
<mx:LinkButton label="{dg.selectedItem.courseName}" click="navigateToURL(new URLRequest(dg.selectedItem.courseURL),'_blank');"/>
</mx:Application>


thanks in advance
tdurant is offline   Reply With Quote
Old 05-19-2008, 02:28 PM   #3
tdurant
Registered User
 
Join Date: May 2008
Posts: 4
Wink fix

I was able to figure it out with some help from other tutorials. Instead of using a http service I turned it into an xml list collection and formating it e4x. here's the code for newbies who had the same problem I had.

mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Script>
<![CDATA[
private function filterFunc(item:Object):Boolean {
return item.text().match(new RegExp("^" + acronymNameFilter.text, "i"));
}
]]>
</mx:Script>

<mx:XML id="dp" source="data/acronyms3.xml" format="e4x" />

<mx:XMLListCollection id="xmlListColl" source="{dp.acronymInfo.acronym}" filterFunction="filterFunc" />
<mx:Canvas height="220">

<mx:VBox>
<mx:HBox width="100%">
<mx:Label text="Name:" />
<mx:TextInput id="acronymNameFilter" width="100%" change="xmlListColl.refresh()" />
</mx:HBox>

<mxataGrid id="dataGrid" dataProvider="{xmlListColl}" x="20">
<mx:columns>
<mxataGridColumn id="codeCol" dataField="*" headerText="acronym:" width="65" />
<mxataGridColumn id="nameCol" dataField="@desc" headerText="Description" width="280" />
</mx:columns>
</mxataGrid>
<mx:Label text="Filtered: Showing {xmlListColl.length} record(s)" visible="{acronymNameFilter.text.length > 0}" />
</mx:VBox>
</mx:Canvas>
<mx:Label x="0" y="241" text="Acronym Search" fontFamily="Arial" fontSize="18"/>
</mx:Panel>

xml sample:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<acronymData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<acronymInfo>
<acronym desc="Automated Area Distribution Center">AADC</acronym>
</acronymInfo>
<acronymInfo>
<acronym desc="Automated Barcode Evaluator">ABE</acronym>
</acronymInfo>
tdurant is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid LinkButton Itemrenderer data setup RR_QQ Flex 2, 3 & 4 2 01-21-2009 07:01 PM
Can you create a DataGrid soley in code using new DataGrid(); frank grimes Components 3 04-16-2007 07:31 AM
Proper way to bind data to the DataGrid component - Best practices. andrea_muta Components 1 04-03-2007 09:13 AM
Datagrid Scrolling bug? Column repeats over and over while mouse is pressed... diesel5599 Components 2 12-18-2006 04:34 PM
Please help loading data/ datagrid ericb1 Components 1 11-22-2005 07:26 PM


All times are GMT. The time now is 11:39 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.