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


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


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.


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 :)

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »