3 Replies Latest reply on May 23, 2008 5:30 AM by bre358

    filterFunction woes

    bre358
      Okay, I'm working on a filter function to sort through information in an
      ArrayCollection which is filled by the results of a select statement to
      a database. The actual functionaility is modified ever so slightly from
      the source I found here:

      http://www.franto.com/blog2/wp-content/uploads/examples/filterfunction/s\
      rcview/

      This is what I have:
      ------------------------
      private function filterProducts():void
      {
      model.prodMaintData.filterFunction = sortProducts;
      model.prodMaintData.refresh();
      }

      private function sortProducts(item:Object):Boolean
      {
      var value:String;
      var col:String = this.cmbColumns.selectedItem.data as String;
      searchBy = this.txtDescription.text;

      searchBy = searchBy.toLowerCase();

      if (searchBy != "")
      {
      if (col != "any")
      {
      value = item[col]; //Why is value NOT getting set
      equal to this?
      value = value.toLowerCase(); //Error happens here
      because value is still null for some reason

      if (value.indexOf(searchBy) >= 0)
      {
      return true;
      }
      }
      else
      {
      for (var o:String in item)
      {
      value = item[o];
      value = value.toLowerCase();
      if (value.indexOf(searchBy) >= 0)
      {
      return true;
      }
      }
      }
      }
      else
      {
      return true;
      }

      return false;
      }
      ------------------------

      Now, as seen by my comments, I keep getting an error because the value
      variable is null for some reason, even when lines were changed around
      from what was originally from the sample. I don't know if this has
      anything to do with it, but despite the fact that my comboBox is
      populated by an ArrayCollection that was declared and filled manually in
      the code:

      ------------------------
      columnArray = new ArrayCollection();
      columnArray.addItem({data:'any', label:'Any'});
      columnArray.addItem({data:'productID', label:'Product ID'});
      columnArray.addItem({data:'productName', label:'Product
      Name'});
      columnArray.addItem({data:'print', label:'Print'});
      columnArray.addItem({data:'barcode', label:'Barcode'});
      columnArray.addItem({data:'vendor', label:'Vendor'});
      columnArray.addItem({data:'status', label:'Status'});
      ------------------------

      The ArrayCollection which populates the dataGrid, the one I'm trying to
      sort through, is instantiated and populated automatically again from a
      database table. I don't see the reason why the value variable should be
      null and causing the error. Thanks in advance.

      Brian Ross Edwards