Multiple filter [Flex Example]

In this example I show an easy way to filter an ArrayCollection with multiple conditions, it can also be applied to XMLListColletions. Filters are given by the DropDownLists and the result is shown in the DataGrid.

Source here:
[RAW] id="fm_Ex_Filter_2031413492"
class="flashmovie"
width="573"
height="268">

Get Adobe Flash player



[/RAW]

I created this function to filter the data, it loops through the files and if all the conditions are respected returns true:

[code lang="as3"]
private function peopleFilter(item:Object):Boolean {
var risp:Boolean=new Boolean;
if (sexFilter.selectedIndex == 0 || item.sex == sexFilter.selectedItem) {
if (hairFilter.selectedIndex == 0 || item.hairColor == hairFilter.selectedItem) {
if (ageFilter.selectedIndex == 0 || item.age >= ageFilter.selectedItem) {
return true
}
}
}

return false;
[/code]

the same can be done in a more professional way, creating an ArrayCollectionExtended Class as explained in this tutorial, but afterwards I had some problems passing the data from MySQL into the new ArrayCollectionExtended.

So, maybe you prefer the easy way too ;).

One Response to Multiple filter [Flex Example]

  1. Xeroo says:

    WOOOT thanks! This just saved my day!! I encountered the same problem with sorting data when its provided by MySQL.. It works now though! Thanks again peace out

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Home
Twitter Facebook Flickr Vimeo About me Email me