Hi Brian,

The original example uses an associative array; which is an instance of
the Object class.  Because the example creates it's ArrayCollection in
code, value = item[col] works:

dpRows = new ArrayCollection();
var item:Object = new Object();
item.type = "Website";
item.name = "Expectal.com";
item.url = "http://www.expectal.com";;
item.desc = "Your Professional Flash Photo Gallery with Slideshow and
Background Music";
item.tags = "Flash, Gallery, Slideshow, Music";
dpRows.addItem(item);

However, if you are loading your DataGrid's ArrayCollection from a
database, it's probably not being returned in an associative array
format.  If it is, check to make sure that the field names are exactly
the same as the "data" values in the ComboBox ArrayCollection.  If it's
not, you will probably have to re-write the code to be conditional.  You
might also want to debug the "col" variable; to make sure that it
contains a value.

As a general recommendation, I would pay attention to naming
conventions.  Filters and Sorts are two distinctly different functions
that may be applied to an ArrayCollection. 
(model.prodMaintData.filterFunction = sortProducts is confusing).  Also,
I would stay away from using the word "data" in name/value pairs.  It
works, but it's very close to being a reserved word in Flex.

-TH

--- In [email protected], "bredwards358" <[EMAIL PROTECTED]>
wrote:
>
> 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
>


Reply via email to