Regex – Flex : Filter a datagrid using a combobox value that is contained in a datafield

apache-flexcomboboxdatagridfilterregex

I have a filter in a combobox with a number of entries. Instead of filtering the datagrid with an exact match, I would like to take the selected value and only display records where the selected value is contained in the datafield.
For example: the user selects a value of "New" and the datagrid displays records where the contents of the record could be "New User", "New Person", "This one is New" etc.
I think that I need to use RegExp, but I cant work out how to get it to work.
Thanks in advance,
S…

Best Answer

Something like this should work:

 public function filter(item:Object):Boolean{
        var result:Boolean=false;
        if (item.name.toUpperCase().indexOf(cbo.selectedLabel.toUpperCase()) >= 0)
             result=true;
        return result;
 }

This filter function will search the name attribute(or whatever you want to filter on) of the object passed in with the combobox's currently selected label and if it finds that value it will return true. So if it finds the word "New" anywhere in the string it will show up in the datagrid. IE: "New Person", "New User" will both show up once filtered.

Hope this is what you are looking for.

Related Topic