Alex, i have an arraycollection (archiveAr) which i would like to filter based
on the following multiple parameters; Keywords, title and subject. i would like
to use 3 textinputs to do this. one for keywords, another for title and the
last one for subject. Now i can only use one textinput to filter based on
keywords and would like to have all of them filter the array collection
depending on the users choice. below is the code i have so far. someone please
help.
/******************* code to get Archives *****************************/
//[Bindable]
private var archiveAr:ArrayCollection=new
ArrayCollection();
/* [Bindable]
private var filteredAr:ArrayCollection = new
ArrayCollection(archiveAr.toArray()); */
[Bindable]
private var filteredAr:ArrayCollection=new
ArrayCollection();
private function archiveResult(event:ResultEvent):void
{
archiveAr=event.result as ArrayCollection;
//filteredAr=event.result as ArrayCollection;
}
/******************* Start Filter Functions
***************************/
private var keywordText:String="keywords";
private function filterGrid():void
{
archiveAr.filterFunction=myFilterFunction;
archiveAr.refresh();
for (var i:int=archiveAr.length - 1; i >= 0;
i--)
{
if (!filteredAr.contains(archiveAr[i]))
{
filteredAr.addItem(archiveAr[i]);
}
}
for (i=filteredAr.length - 1; i >= 0; i--)
{
if (!archiveAr.contains(filteredAr[i]))
{
filteredAr.removeItemAt(i);
}
}
}
private function filterReset():void
{
archiveAr.filterFunction=null;
archiveAr.refresh();
}
private function myFilterFunction(item:Object):Boolean
{
return item[keywordText].match(new
RegExp(generalSearch.text, 'i'));
//return item[keywordText].match(new
RegExp("^"+generalSearch.text, 'i'));
}
private function keywordChangeHandler(event:Event):void
{
if (generalSearch.text != '')
{
filterGrid();
}
else
{
filterReset()
}
}