4 Replies Latest reply on Jul 17, 2008 2:52 PM by bitwyse

    AS3, filtering dataset on the client

    cheftimo Level 2
      Hello again, friends:

      Still playing with cartoons, I am working on a different way to browse them. The application is here, http://www.timos.com/timos/GreenEarthEN/GreenEarthEN.html and View Source is enabled for the relevant code.

      I want to be able to browse the cartoons by category (the subject each one deals with) – this would be the data grid column called "Keywords". Some of the cartoons are relevant to more than one keyword, so the keywords fields are really LISTS. The combo box above the data grid view lets you choose a keyword to fetch the relevant cartoons. Every time you select a new keyword in the ComboBox, a call is made to the server to get the new filtered list. Manipulating these lists is very easy with ColdFusion and/or SQL.

      Since the entire dataset comes into the app on CreationComplete and is always available, it would be smarter to do all the filtering on the client. I have searched all the Adobe docs and googled all I could think of, but found very little about filtering data with ActionScript.

      Any ideas about how to do this would be highly appreciated. If you wish to give this a shot, keep in mind we are dealing with lists, not single keywords.

      Best to all,

        • 1. AS3, filtering dataset on the client
          VarioPegged Level 2
          Using a filterFunction on your ArrayCollection is probably the simplest way to go. I've only glanced at your code, but see if this works for you.

          • 2. Re: AS3, filtering dataset on the client
            Rob Rusher Level 1
            I agree with VarioPegged, with one exception. You need to add a reset on the filter for when the "All" is selected.
            I've cleaned up the code a little as well. This should be a lot better than going for the data each time the ComboBox is changed.
            • 3. Re: AS3, filtering dataset on the client
              cheftimo Level 2
              I don't know what we noobs would do without the kind people who frequent these forums and give us invaluable help. The help systems are not that smart: I found nothing by searching for things like 'AS 3 data filter', 'Flex filter' and several variations of those; I never thought of 'filter function', much less 'filterFunction' – searching for those, I did find a lot of material. But that's moot when you don't know or think of the term.

              TS's reply was exactly what I needed. Re the code for when "All" is selected, I just removed it from the CFC, since Rob added it to the mxml file; now the thing is working like a little Swiss watch. I will put it on the web server after I do some styling and other things.

              Rob, you did a lot more than I expected, rewriting the whole Application file – great "customer service".

              TS and Rob, thank you very much for all this help. Contact me when you need a recipe. Best regards,

              • 4. Re: AS3, filtering dataset on the client
                bitwyse Level 1
                Just to throw in my two cents on this, I do something similar, however, I use a regular expression search. As you can see below it's pretty simple, I"m searching all the fields in my passed in items Object ( which is a row in a datagrid ) case insensitive . So now the user can search for any text in any row / column of my data grid. Using RegExp allows more options if you need when searching text. Here I'm only using case insensitivity but you could easily add masking, or more complicated expressions.

                private function filterRoutine( items : Object ) : Boolean
                for each( var anItemValue : String in items )
                if( anItemValue != null )
                if( anItemValue.match( new RegExp(searchField.text, 'i' ) ) )
                return true
                return false;