0 Replies Latest reply on May 23, 2012 4:50 AM by Rohith S

    Filtering Flex Tree Using XmlList

    Rohith S

      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'm very new to the flex. need help ASAP


      Warm Regards.

       

       

      <?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>