Filter Function for cf flash forms

Use this to filter data in a datagrid

I always get scared that asfusions blog isn’t going to be available, one day i went there, and the blog and examples part was totally gone, i was freaking out, i go there as a reference all the time… Here is a function i use alot, and so i’m going to blog it as well as it is available on asfusion.com

when i get some time i’ll see if this code works, sometimes when copying and pasting the code into this blogger software i use… some lines dont go in right… but i know it works, because i use it on… beta.killtheheart.com

function applyFilter( term:String, grid:mx.controls.DataGrid, columns:Array ):Void {

var filterTerm:String = term.toString().toLowerCase();

if(filterTerm.length > 0) {

if(_global.unfilteredData[grid.id] == undefined){

if (_global.unfilteredData == undefined){

_global.unfilteredData = {};

}

_global.unfilteredData[grid.id] = grid.dataProvider.slice(0);

}

var filteredData:Array = [];

for(var i = 0; i< _global.unfilteredData[grid.id].length; i++) {

var item:Object = _global.unfilteredData[grid.id][i];

var added:Boolean = false;

for(var j = 0; j< columns.length; j++){

if(!added){

var value:String = item[columns[j]].toString().toLowerCase();

if(value.indexOf(filterTerm) != -1) {

filteredData.push(item);

added = true;

}

}

else {

break;

}

}

}

grid.dataProvider = filteredData;

}

else {

if(_global.unfilteredData[grid.id] != undefined) grid.dataProvider = _global.unfilteredData[grid.id];

}

}

1 comment on this post.
  1. tony:

    can you use this filter on a cfselect list?

Leave a comment