I have a MXList Box having arrayCollection and I have another textarea box.
My requirement is: When users enter the desired text in the text area, I need to fetch and show the matching records from the List like:
___________
|____Ka___| Text area
__________
|Kanrna |List Box : ArrayCollection
|Kam |
|Kao |
|kaddsd |So it looks something like this
|_________|
I have tried with various approaches:
<mx:List id="availableProfileList"
dataProvider="{campaignProxy.campaignWizardVo.currentProfiles}""/>
<mx:TextArea id="textSearch" textInput="applyFilter()"/>
protected function applyFilter():void{
campaignProxy.campaignWizardVo.currentProfiles.filterFunction = matchingFunction(campaignProxy.campaignWizardVo.currentProfiles, textSearch.text);
//Alert.show(textSearch.text)
//availableProfileList.findString(textSearch.text);
//availableProfileList.setFocus();
}
public function matchingFunction(availableProfileList:List, text:String):Vector.<int> {
var results:Vector.<int> = new Vector.<int>;
var item:String;
var entered:String = text.toLowerCase();
var itemIdx:int;
Alert.show("before for");
for(var idx:int = 0; idx < availableProfileList.dataProvider.length; idx++) {
item = availableProfileList.dataProvider.getItemAt(idx) as String;
item = item.toLowerCase();
itemIdx = item.indexOf(entered);
if(item.indexOf(entered) > -1) {
results.push(idx);
}
}
return results;
}
After checking these questions:
combobox which filters dataprovider based on user input and:
Flex - Search/Filter DataGrid by Text Input
I still don't understand how to make it work.