Some one online mailed the flexcoders yahoo list and asked for some assistance… I took this as a challenge, because I have been assigned at work to do some similar tasks within the near future, and I thought this was a perfect opportunity to get some practice in.

http://axelscript.com/wp-content/cfwtExamples/Taftp/bin/main.html (right click to view source)

Many of us want to use flex because of it’s great filtering data (on the client) capabilities. I’ve been doing some research on filtering data, and more complex filtering capabilities, and filtering data has always been a challenge in my mind.

Maybe I am just far too inexperienced in this area, but I always have trouble deciding what the order of importance is, for example.


I have a form with a datagrid, and this datagrid shows 3 columns.

-Employee Name
-Region (that they are located in)
-Category (of employee that they are)
I want to be able to search any of these fields, so I start typing in some text box expecting my datagrid to filter properly… Lets say the text box filters out the name field… and I have a series of check boxes that I want to filter the Regions off, and I have a multiple select List that I would like to filter my categories off… I have all of this working as of right now by referring to the link above, and right clicking to view the source, you’ll be able to get a better idea. One of the issues that I am having in this scenario is:

I uncheck all of my Regions, and the list goes blank… thats fine, but say I want to view all of the Programmers in the list, so I select “Programmer” and then click my Process Filter button, then that lets me view all of my programmers… say i want to only view all of the programmers in Austin So I check Austin, but in the list I get:

All of the Employees that are in the “Programmer” category, as well as ALLL of the Employees that are in Austin… the main filter that I have doing this needs some public assistance, that I’m turning to the groups for.

// Filter function
public function processFilter(item:Object):Boolean{
var result:Boolean=false;
getRegions(); // returns “1,2,3
getCategories(); //returns “2,3,4
trace(‘item.regionID : ‘ + item.regionID);
trace(‘item.catID : ‘ + item.catID);
if(regArray.length){
for (var i:String in regArray) {
trace (‘regArray[i] : ‘ + regArray[i]);
// If no filter text, or a match, then true
if (item.regionID.toString() == regArray[i].toString()){
result=true;
}
}
}

if(catArray.length){
for (var k:String in catArray) {
trace (‘catArray[k] : ‘ + catArray[k]);
// If no filter text, or a match, then true
if (item.catID.toString() == catArray[k].toString()){
result=true;
}
}
}

return result;
}

there is the main line of filter work

if (item.catID.toString() == catArray[k].toString()){
result=true;
}

that verifies that the data being passed is equal to the data that you want to see… I need an “or” statement in here to resemble the following

if (item.catID.toString() == catArray[k].toString() ||
item.catID.toString() == regArray[i].toString()
){
result=true;
}

I just can’t quite get my mind wrapped around what I need to do, But this is a great start on the issue… I just need to do. I think i’m going to need a few different if statements:

one that decides if both the categories and regions are being used to filter, then have the main filter line do something

one that states if the catArray.length is false, then do something with that main filter line

one that does the same for the regArray.length as well…

that might do the trick or at least get it started, but anyone out there that has came across this and cares to help a fellow programmer out… It would be very much appreciated!

Thanks a lot for taking the time to read this.