4 Replies Latest reply on Jun 4, 2008 9:22 PM by Sreenivas R

    Filtering a tree

      I'm having some problems filtering a tree in flex 3.0. The tree's dataprovider is an XmlListCollection. I've created a filterfunction which filters the data based on user input in a text field. My problem is that it's only run on the first level of my tree and not any of the childnodes.

      Here is the code I use:

      private function filterFunc(item:Object):Boolean {
      var xmlData:XML = XML(item);
      var searhReg:RegExp = new RegExp("^" + searchText.text, "i");
      var searchIndex:int = item.@label.search(searhReg);
      return searchIndex > -1;

      And this is my Tree and XmlListCollection:
      <mx:XML id="xmlMenu" source="menu.xml"/>
      <mx:XMLListCollection id="xmlMenuList" source="{xmlMenu.*}" filterFunction="filterFunc" />

      <mx:Tree id="treeLinks" fontSize="10" dataProvider="{xmlMenuList}" itemClick="klikItem(event)" labelField="@label" x="10" y="40" width="357" height="337">

      The xml I use looks like this:
      <node label="node1">
      <node label="subnode1"/>
      <node label="subnode7"/>
      <node label="node6">
      <node label="subnode1"/>
      <node label="subnode7"/>

      Hope someone out there can help me with this.