2 Replies Latest reply on Oct 1, 2012 7:58 AM by John Hall

    Trouble with filterFunction

    John Hall Level 4

      I usually have no problem with an ArrayCollection filterfunction. I have one instance where the code is the following:

       

      itemsToDisplay = timeslotPM.timeslots;

      itemsToDisplay.filterFunction = filteredBySelected;

      itemsToDisplay.refresh();

       

       

      protected function filteredBySelected( item : Timeslot ) : Boolean {

                                              if ( currentState == "masterCalendar" && includeEmptyCheckbox.selected == false && item.isScheduled == false ) {

                 Logger.info("NO"); // traces no fine and when I debug the app it goes through this branch and shows false for about half the items

                 return false;

                                              }

        Logger.info("YES");

        return true;

      }

       

      Yet, the length of the ArrayCollection never changes, despite the filter function returning false on half the items. I've searched for other code across the application that might set a filterFunction to null, but no go.

       

      Any other suggestions on how to debug this problem?

        • 1. Re: Trouble with filterFunction
          jfb00 Level 3

          Hi,

          Try the next code, where you if statement (try debug) validates and keep the item in the arrayCollection.

           

          protected function filteredBySelected( item : Object) : Boolean {

               for each (var area:Object in item) {

                     if ( currentState == "masterCalendar" && includeEmptyCheckbox.selected == false && item.isScheduled == false ) {

                          Logger.info("NO"); // traces no fine and when I debug the app it goes through this branch and shows false for about half the items

                          return true;

                         break;

                      }

               }

            Logger.info("YES");

            return false;

          }

           

          I hope this help.

          Best,

          • 2. Re: Trouble with filterFunction
            John Hall Level 4

            Thanks for your input.