Hi,
I want to filter ArrayCollection based on multiple values ( or array ). For example, My sample array "myArray" has four values; Active, Close,Returned and Submitted.
My code looks like,
sampleData.filterFunction =doStatusFilter
sampleData.refresh();
public function doStatusFilter(item:Object):Boolean {
var i:int;
var query:String;
var sep:String
query="(";
sep=""
for (i=0; i<myArray.length; i++) {
query=query+sep+(item.status + "=='"+ myArray[i]+"'");
sep=" || ";
}
query=query+")";
//Here is my problem..Since return type is boolean
return query
}
I can build query successfully but how do I execute "query" ?
I need to filter my collection based on multiple status.
Updates:: Here is solution ....
package com.rish
{
public class FilterSelector
{
import mx.controls.*;
private var _filterField:String;
private var _filterTypes:Array;
public function FilterSelector(){ /**/ }
public function get filterField():String
{
return _filterField;
}
public function set filterField(value:String):void
{
_filterField = value;
}
public function addFilterTypes(params:Array):void
{
_filterTypes = params;
}
public function generateFilterFunction():Function
{
var f:Function = function(item:Object):Boolean
{
for each(var type:String in _filterTypes)
{
if(item[filterField] == type) return true;
}
return false;
};
return f;
}
}
}
fs = new FilterSelector();
fs.filterField = "status";
fs.addFilterTypes(apStatusArray);
sampleData.filterFunction =fs.generateFilterFunction();
sampleData.refresh();