Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have set xml as a dataprovider to the tree control and it's work fine.
but now i want to filter xml for Tree data provider which ever match with the input text. but filter is not working, So Please any one help me.
I am very new to the flex. need help ASAP

VB
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
          creationComplete="onCreationComplete(event)">
 
          <mx:Script>
                    <![CDATA[
                              import mx.rpc.xml.SimpleXMLDecoder;
                              import mx.collections.ArrayCollection;
                              import mx.controls.Alert;
                              import mx.collections.XMLListCollection;
                              import mx.messaging.management.Attribute;
                              import mx.utils.ObjectUtil;
                              import mx.events.FlexEvent;
 
                              [Bindable]
                              public var dataXML : XML =
                              <ImageGallery >
                                        <Folder Id="0" Name="My Gallery">
                                                  <Image Id="1" Name="Flex" />
                                                  <Image Id="2" Name="Flash" />
                                                  <Image Id="4" Name="Flash" />
                                                  <Image Id="5" Name="Flex4" />
                                                  <Image Id="6" Name="Media"  />
                                                  <Image Id="3" Name="Flex" />
                                                  <Image Id="7" Name="Computer" />
                                                  <Image Id="8" Name="Internet"  />
                                                  <Image Id="9" Name="Firefox" />
                                                  <Image Id="10" Name="Flex" />
                                        </Folder>
                                        <Folder Id="-1" Name="Public Gallery" >
                                                  <Image Id="11" Name="Firefox" />
                                                  <Image Id="12"  Name="Internet" />
                                                  <Image Id="13"  Name="Flex4" />
                                                  <Image Id="14"  Name="Internet" />
                                                  <Image Id="15"  Name="Computer" />
                                                  <Image Id="16"  Name="Internet" />
                                                  <Image Id="17"  Name="Computer" />
                                                  <Image Id="18"  Name="Flash" />
                                                  <Folder Id="-2" Name="Sub Public Gallery" >
                                                            <Image Id="19"  Name="Flex4" />
                                                            <Image Id="20"  Name="Computer" />
                                                            <Image Id="21"  Name="Flash" />
                                                            <Image Id="22"  Name="Flash" />
                                                            <Image Id="23"  Name="Flex4" />
                                                            <Image Id="24"  Name="Internet" />
                                                            <Image Id="25"  Name="Computer" />
                                                            <Image Id="26"  Name="Flash" />
                                                  </Folder>
                                        </Folder>
                              </ImageGallery>;
 
                              private var obj : XMLListCollection = new XMLListCollection();
                               private function onCreationComplete(event:FlexEvent):void
                               {
                                         obj.source = dataXML.Folder;
                                         obj.filterFunction = filterFunc as Function;
                              }
                              private function filterFunc(item:Object):Boolean
                              {
                      var bool : Boolean = item.@Name.match(new RegExp("^" + searchNameInput.text, "i"));
                      return bool;
            }
 
                    ]]>
          </mx:Script>
 
          <mx:VBox height="100%" width="100%">
          <mx:Label text="Search"/>
          <mx:TextInput id="searchNameInput" change="obj.refresh()"/>
          <mx:Tree id="imageTree" name="TreeView" height="100%" width="100%" labelField="@Name" showRoot="false"
                     dataProvider="{dataXML}"  />
          </mx:VBox>
 
</mx:Application>
Posted
Updated 23-May-12 4:12am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900