2 Replies Latest reply on May 9, 2007 11:04 PM by bazjapan

    Filtering array collections

    bazjapan
      I am trying to filter an array collection.
      It is a list of rooms. The rooms have a type, "Boardroom", "Classroom" etc.
      Also they have equipment properties which are set with a boolean value.
      ex. Screen = true, Whiteboard = false etc.

      What I want to do is filter the array collection using multiple conditions.

      Scenario:
      Choose room type from combo. --- this works great :)
      Screen(Check if needed) ---- Here is where my problem lies, When I check the box, the false results are filtered out great! But if I uncheck the box, only the false results are shown. However,I would like to show both true and false results for the screen property. If it is unchecked it means the user is not interested in screens thus the data doesn't need to be filtered for that property.

      I have tried various ways.
      This is where I'm at so far

      private function filterByRoomType():void{

      allRooms.filterFunction = roomTypeFilter;
      allRooms.refresh();
      }
      private function roomTypeFilter(item:Object):Boolean{
      seatingText.text = "+"+seatingSlider.value;
      if(roomTypeCombo.selectedItem=="All"){
      return item.SeatingCap >= seatingSlider.value&&
      item.Desks >= deskSlider.value&&
      item.Beds >= bedSlider.value&&
      item.Screen == screenCB.selected;

      }else{
      return item.RoomType == roomTypeCombo.selectedLabel&&
      item.SeatingCap >= seatingSlider.value&&
      item.Desks >= deskSlider.value&&
      item.Beds >= bedSlider.value&&
      item.Screen == screenCB.selected;
      }
      }

      I have tried changing "item.Screen == screenCB.selected" to "item.Screen == screenCB.selected||false;" but with no joy.
      Once I get the screen checkbox working I would like to increase the amount of checkBoxes(properties) the user can search on.

      This one has got me ripping my hair out, any help would be muchly appreciated
      thanks
      bazjapan

      Oh yes, This is a room object.

      package dto
      {
      [Bindable]
      public class Room
      {
      public var RoomID:int;
      public var RoomName:String="";
      public var RoomType:String="";
      public var SeatingCap:int;
      public var Desks:int;
      public var Beds:int;
      public var Screen:Boolean;
      public var OHP:Boolean;
      public var Sink:Boolean;
      public var FlipChart:Boolean;
      public var Hoist:Boolean;

      public function Room(obj:Object = null)
      {
      if (obj != null)
      {
      this.RoomID = obj.RoomID;
      this.RoomName = obj.RoomName;
      this.RoomType = obj.RoomType;
      this.SeatingCap = obj.SeatingCap;
      this.Desks = obj.Desks;
      this.Beds = obj.Beds;
      this.Screen = obj.Screen;
      this.OHP = obj.OHP;
      this.Sink = obj.Sink;
      this.FlipChart = obj.FlipChart;
      this.Hoist = obj.Hoist;

      }
      }
      }
      }