1 Reply Latest reply on May 14, 2009 12:10 AM by Barna Biro

    ArrayCollection Filtering

    DigitalSpeciaist Level 1

      See the tag filter at the link below:

       

      http://nines.org/tags

       

      Any suggestion on an ArrayCollection filter that can be used to develop a filter search like that?

       

      Thanks.

        • 1. Re: ArrayCollection Filtering
          Barna Biro Level 3

          Hi there,

           

          I can't remember if it's done the same way with an ArrayCollection but for an Array, you'd do this:

           

          /**
           * @private
           * Triggered when the user starts tiping text into the listFilterField.
           */
          private function onFilter(event:KeyboardEvent):void
          {
              // Filter the languages list and set the new array as the dataProvider for the languages list.
              languagesList.dataProvider = _languagesArray.filter(filterText);
          }
          
          /**
           * @private
           * Used to filter the languages list.
           */
          private function filterText(element:*, index:int, arr:Array):Boolean
          {
              // Compare the text typed by the user to the languages list. Return "true" if a match is found, else "false".
              if (String(element.label).toLowerCase().slice(0, listFilterField.text.length) == listFilterField.text.toLowerCase()) return true;
              else return false;
          }
          

           

          The onFilter method is triggered by a KeyUp event that is assigned to a TextInput field ( you can obviously use whatever component you prefer ). Check the language reference and see if ArrayCollection has a "filter" property. I'm quite sure it has something similar if not the exact same thing.

           

          With best regards,

          Barna Biro

          Blog: http://blog.wisebisoft.com