views:

9474

answers:

5

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...

+3  A: 

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.

JustFoo
A: 

I cant vote on the answer (I'm a noobie) but the answer from Just Foo was spot on. Thx.

Please accept as answer then.
Christophe Herreman
A: 

how can we set selected item as selected item of grid(name,mobile,category),if i select one row in grid(category),that selected item(category item) must be selected item in categories comboBox....??? in felx Please help me

Thirst for Excellence
+1  A: 

You can modify this to produce drop down filtering functionality. currently textbox filtering is working. so i am posting it here.

declare 2 string variables tempString and tempString_Name then...

Use the following 2 functions

 private function filterByTerritory(item:Object):Boolean{
        tempString = item.name;
        tempString_Name = item.territory;
        if( (tempString.indexOf(sampleFilter.text,0) != -1) && 
                      (tempString_Name.indexOf(terrFilterTxt.text,0) != -1)){
            return true;
        }
        else{
            return false;
        }
     } 
     private function doFilter():void{
        if( (sampleFilter.text.length == 0) && 
                (terrFilterTxt.text.length == 0)) {
            myData.filterFunction == null;
        }
        else{
            myData.filterFunction = filterByTerritory;
        }
        myData.refresh();
     }

Accept data thru these 2 textboxes

<mx:TextInput id="sampleFilter" change="doFilter()"/>
  <mx:TextInput id="terrFilterTxt" change="doFilter()"/>

nutshell: call doFilter on some event on which u want filtering to happen.

Soon i will post filtering a datagrid based on combo box. Till then bye. I will become a member soon :)

Big 'B'
this is friggin AWESOME and is way better than anything I've seen approaching this. Cheers for this, you saved me such a hassle, I feel like I owe you dinner.
Devtron