1 Reply Latest reply on May 15, 2007 7:52 AM by BLXWebMaster

    how to filter arraycollection returned from cfc

      I am having trouble filtering an arraycollection returned from a query in a cfc. I know i have to use the filter function from the arraycollection class, but dont know exactly how to reference the tables from my database in my flex application.
      anyhelp on this would really be apreciated
        • 1. Re: how to filter arraycollection returned from cfc
          BLXWebMaster Level 1
          I am not sure exactly what you are trying to do, specifically what and how do you want to filter.

          Typically your CF Component would return a query object that is then used in your Array.

          private var arQuery:ArrayCollection = null;

          private function getQueryReceived(event:ResultEvent):void {
          arQuery = new ArrayCollection();
          arQuery = event.result as ArrayCollection;

          After your ArrayCollection you call the filterFunction. This is a sample that I use to filter based on what is selected in a ComboBox and a TextInput. The "FieldName" would be replaced with the actual field name you want to filter on. This is exactly how the query is returned. Remember it is Case Sensitive.

          public function processFilterQueryitem:Object):Boolean {
          var result:Boolean=false;
          if ((cbCategory.selectedLabel == 'Show All' || (item.FieldName != null && item.FieldName.toUpperCase().indexOf(cbCategory.selectedLabel.toUpperCase()) >= 0)) &&
          (textName.text == '' || (item.FieldName != null && item.FieldName.toString().indexOf(textName.text) >= 0)))
          return result;

          So, now anytime you call the arQuery .refresh(); the filter will be applied. So, if you want to filter on a text input box, add arQuery.refresh() to the onChange event and you can filter your DataGrid dynamically as you type.