• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Datagrid filtering

New Here ,
Apr 14, 2009 Apr 14, 2009

Copy link to clipboard

Copied

Howdy

I've been trying for the past couple of days to figure out how use a button (or movieclip) to filter information out of a datagrid based on an external XML document. For example, say, the data were types of fruit along with their corresponding prices, but the user was only interested in the price of apples. To see only those records or rows with apples and the corresponding apple prices, the user would press the "Apples" button, if that makes sense.

Creating the datagrid seems pretty straight forward, it's just the second part that's stumped me. Whatever the answer is would seem to go at the end where the "trace" is now. There seems to be many, many Web sites that sort of touch on this subject, and even if you can't provide the actual code, if you could just point me to a good resource for this I'd be very appreciative.

I typed of the following from memory (I'm at work now), but I think this is pretty much what I have so far.

Thanks again!

--k

import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;

var food:XML;
var urlLoader:URLLoader;
var urlRequest:URLRequest = new URLRequest("food_list.xml");
urlLoader = new URLLoader();
urlLoader.load(urlRequest);


var fruitCol:DataGridColumn = new DataGridColumn("fruit");
fruitCol.headerText = "Fruit";
fruitCol.width = 120;
var priceCol:DataGridColumn = new DataGridColumn("price");
priceCol.headerText = "Price";
priceCol.width = 60;

urlLoader.addEventListener(Event.COMPLETE, loadingDone);

function loadingDone (e:Event):void
{
        food = new XML(urlLoader.data);       
        var myDP:DataProvider = new DataProvider(food);

        aDg.columns = [fruitCol, priceCol];
        aDg.width = 240;
        aDg.dataProvider = myDP;
        aDg.rowCount = aDg.length;
}

apples_mc.addEventListener(MouseEvent.CLICK, showFresh);

function showFresh (e:Event):void
{
    trace("hello");

}

TOPICS
ActionScript

Views

434

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 14, 2009 Apr 14, 2009

Copy link to clipboard

Copied

You wouldn't want to reduce the Datagrid, instead you would reduce the XML, and rebuild the datagrid from scratch. For example, this xml:

<xml>

<fruits>

  <fruit type="apple" description="Granny Smith" cost="0.50"/>

  <fruit type="apple" description="Golden Delicious" cost="0.70"/>

  <fruit type="orange" description="Jaffa" cost="0.50"/>

  <fruit type="orange" description="Florida" cost="0.50"/>

  <fruit type="pear" description="Shape" cost="0.50"/>

</fruits>

</xml>

could be reduced to just apples like this:

var justapples:XMLList = xml.fruits.fruit.(@type=="apple");

and you would then rebuild your datagrid with those entries.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2009 Apr 15, 2009

Copy link to clipboard

Copied

LATEST

thanks, I'll give it a try

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines