Search:
  • Home
  • Examples
    • Thumb

      Flex Examples

      Check out our Flex Examples!

    • Thumb

      Flash Builder Examples

      Check out our Flash Builder Examples!

    • Thumb

      AIR Examples

      Check out our AIR Examples!

    Adobe® Flex, Adobe® Flash Builder and Adobe® AIR are registered trademarks of Adobe Systems.
  • Components
    • Thumb

      WP Flex Contact Form

      Check out our WP Flex Contact Form!

    • Thumb

      Flash CountDown Plugin

      Check out our Flash CountDown Plugin!

    This is an overview of all our Flash/Flex based Components.
  • Jobs
  • Guest Poster
  • Forum
  • Contact Us
Subscribe to Flex BlogSubscribe
  • Examples
Browse > Home / Examples / ArrayCollection Filter Example

ArrayCollection Filter Example

17 November 2009

Line Break

Author: Roelof (11 Articles) - Author Website

Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer, travelling or just being lazy. He is also the co-owner of Flex-Blog.com.


This example is all about filtering an ArrayCollection in a DataGrid. We will filter the ArrayCollection using the input from the TextInput field, the value entered as the datagrid values are translated to lower case.

The search is performed without position, this means that if I type ‘weaver’ in the search box, i will find ‘Dreamweaver’ in my results.

Here is the example: (Source can be viewed underneath the example or via Right Mouse Click -> View Source ).

The (almost) complete source code is right here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/halo"
               initialize="init()"
               width="500" height="300" viewSourceURL="srcview/index.html">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
   
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
           
            [Bindable]
            private var myArrayCollection:ArrayCollection;
           
            private var firstTime:Boolean = true;
           
            private function init():void {
                myArrayCollection = new ArrayCollection;
                var obj:Object = new Object;
               
                obj.product = "Photoshop CS4";
                obj.instock = "4";
                myArrayCollection.addItem(obj);
                obj = new Object;
                obj.product = "Dreamweaver CS3";
                obj.instock = "8";
                myArrayCollection.addItem(obj);
                //etc
            }
           
            private function filter():void {
                myArrayCollection.filterFunction = filterMyArrayCollection;
                myArrayCollection.refresh();
            }
           
            private function filterMyArrayCollection(item:Object):Boolean {
                var searchString:String = myTextInput.text.toLowerCase();
                var itemName:String = (item.product as String).toLowerCase();
                return itemName.indexOf(searchString) > -1;
            }
           
            private function clearMyTextInput():void {
               
                if (firstTime == true )
                {
                    myTextInput.text = "";
                    firstTime = false;
                }
            }
           
        ]]>
    </fx:Script>
   
    <mx:VBox right="10" left="10" bottom="10" top="10">
        <s:TextInput id="myTextInput" change="filter()"
                     enabled="true"
                     focusIn="clearMyTextInput()"
                     text="Filter/Search.."
                     width="100%" height="26"/>
       
        <mx:DataGrid id="dataGrid"
                     dataProvider="{myArrayCollection}"
                     verticalScrollPolicy="on" dropShadowVisible="false" verticalAlign="top" editable="false" width="100%" height="80%" paddingTop="2">
            <mx:columns>
                <mx:DataGridColumn dataField="product"  headerText="Product"/>
                <mx:DataGridColumn dataField="instock"  headerText="In Stock"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:VBox>

</s:Application>

Related posts:

  1. Looping over an ArrayCollection with Cursor Example
  2. Style AdvancedDataGrid depending on data example
  3. Progressbar in Datagrid Example
  4. Images in DataGrid depending on data
  5. Drag and Drop from DataGrid or AdvancedDataGrid to Tree

Written by Roelof · Filed Under Examples 

Was this post useful to you?

1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 4.71 out of 5)
Loading ... Loading ...

Comments

2 Responses to “ArrayCollection Filter Example”

  1. ajai robin on June 11th, 2010 8:42 am

    Thanks Roelof…. the post was really helpfull….

  2. Roelof on July 5th, 2010 3:28 am

    hi, this is very helpfull. thanks for the wonderful post.

Get Adobe Flash player

  • Sponsors

  • Popular Tags

    • AdvancedDataGrid
    • AIR
    • ArrayCollection
    • baseColor
    • Button
    • ButtonBar
    • ComboBox
    • CursorManager
    • DataGrid
    • Effects
    • File
    • Flash Builder
    • Flash Builder 4
    • Flashvars
    • Flex 4
    • HSlider
    • Icon
    • Image
    • itemRenderer
    • LinkBar
    • MouseWheel
    • PHP
    • ProgressBar
    • Repeater
    • Style
    • Timer
    • Tree
    • Twitter
    • ViewStack
    • VSlider
  • Flex Blog Readers

  • Testing..

  • Flex Jobs (from Flex Jobs.org)

    Your Job here? Post your job @ Flex Jobs.org

    Advertisement

  • Recent Posts

    • How to make a magnetic button in Flex 4
    • Using ASDoc as an External Tool in Flash Builder 4
    • Flex Encryption (MD5, SHA1, SHA224, SHA256, HMAC)
    • The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull
    • Call Javascript function from Flex / Flash Builder (AS3)
    • Flex FlashVars in AS3 Example
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction
    • WordPress Flash / Flex Comments Form
    • Adobe AIR SQLite Example
    • Flex 4 Effect Example: Sliding text using the Move Effect
  • Categories

    • Examples
    • Guest Poster
  • Archives

    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • March 2009
    • February 2009
  • Blogroll

    • Adobe Flex Jobs
    • NL for Business
  • Meta

    • Register
    • Log in
    • WordPress
    • XHTML

Copyright © 2010 Flex Blog · AdobeĀ® and AdobeĀ® Flex are registered trademarks of Adobe Systems.

WordPress Adobe Flex Adobe Flash Builder Adobe AIR Creative Commons License

  • Popular Posts

    • Progressbar in Datagrid Example 6 votes, average: 5.00 out of 56 votes, average: 5.00 out of 56 votes, average: 5.00 out of 56 votes, average: 5.00 out of 56 votes, average: 5.00 out of 5 (5.00 out of 5)
    • List Directory with AIR in Flex 4 6 votes, average: 5.00 out of 56 votes, average: 5.00 out of 56 votes, average: 5.00 out of 56 votes, average: 5.00 out of 56 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction 5 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Control Webpage in HTML Control in AIR 4 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 5 (5.00 out of 5)
    • WordPress Flash / Flex Comments Form 4 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 5 (5.00 out of 5)