:: Forum >> Version 2 >>

Filter rows in CSV file

I have a 4 column grid. one column is called Publisher. i want to filter all rows in grid where Publisher="IBM". does anyone have any idea on how to do this with a CSV file. thanks for your help!!!!
Matt
Tuesday, March 9, 2010
Alex posted a simple example here (that is also valid for csv data model):
/javascript.forum.8149.8/filtering-rows-example.html
I managed to tune it in just two minor changes:
max = table.getCount(); instead of obj.getRowCount(); ( for xml and csv data models), and last line obj.getRowsTemplate().refresh();
It also allows reseting the filter by pasing an empty search string.

// var max = gridVar.getRowCount();   ///// FOR ARRAY DATA MODEL
// var max2 = max;   //////  FOR ARRAY DATA MODEL
  
    
function filter(textcolumn){

    var 
irows = [], max table.getCount();   /////////  FOR ARRAY DATA MODEL USE: (in new line) max = gridVar.getRowCount(); 

 
if (text==''){
     
obj.setRowCount(max);    /////////  FOR ARRAY DATA MODEL USE: max2
    
obj.setRowIndices('');
 }
 if (
text !=''){
    for (
i=0i<maxi++){   /////////  FOR ARRAY DATA MODEL USE: max2
        
if (obj.getCellValue(columni).indexOf(text)> -){
            
rows.push(i);
        }
    }
    
obj.setRowCount(rows.length);
    
obj.setRowIndices(rows);
}
    
obj.getRowsTemplate().refresh();
But if you need to filter on more than one column ( acumulative / nested filter) you can also use this one:
Note: to reset all filters here, you need to empty the array filtersrunning = [] and also call the function with an empty string NestedFilter('');

// var max = gridVar.getRowCount();   /////////  FOR ARRAY DATA MODEL
  // var max2 = max;   /////////  FOR ARRAY DATA MODEL
  
var filtersrunning = [];

function 
NestedFilter(searchcriteria,column){ 

searchcriteria searchcriteria.toUpperCase();
var 
filters filtersrunning ;
var 
irows = [], max table.getCount(); /////////  FOR ARRAY DATA MODEL USE: (in new line) max = gridVar.getRowCount(); 

var samecolfound false;

if(
filtersrunning.length == && searchcriteria !=''){ filters.push([column,searchcriteria] ) }

if(
filtersrunning.length ){ 
for(var 
aa=aa<filtersrunning.length aa++){ 
if(
filtersrunning[aa][0] == column){samecolfound true 
}  
for(var 
z=z<filtersrunning.length z++){ 
if(
samecolfound ){ 
if(  
searchcriteria !='' && filtersrunning[z][0] == column  ){ filters[z]=[column,searchcriteria] } 
 if( 
searchcriteria=='' && filtersrunning[z][0] == column  ){ filters.splice(z,1) } 
 } 
  } 
  if( !
samecolfound ){ 
 if( 
searchcriteria !=''){  filters.push([column,searchcriteria] ) } 
 } 
}  

if(
filters.length == ){
obj.setRowCount(max); /////////  FOR ARRAY DATA MODEL USE: max2
obj.setRowIndices(''); 
//Lab.setControlText("FOUND: " + max);
obj.setRowCount(rows.length); 
}

if(
filters.length ){
 for (
rw=0rw<maxrw++){    /////////  FOR ARRAY DATA MODEL USE: max2
 
var found =0;
  for (
Xcol=0Xcol<filters.lengthXcol++){ 
   if ( 
obj.getCellText(filters[Xcol][0], rw).toUpperCase().indexOf(filters[Xcol][1]) >-){ 
   
found++ ;
}
}        
if (
found== filters.length) { rows.push(rw) }


obj.setRowCount(rows.length); 
obj.setRowIndices(rows); 
//Lab.setControlText("FOUND: " +rows.length);
}
filtersrunning filters;
//Lab.refresh();
obj.getRowsTemplate().refresh();
You can find more about both...
/javascript.forum.22570.11/need-help-with-filter-based.html
and here respectively:
/javascript.forum.25833.28/column-header-dropdownbox-filter-example.html
HTH
Carlos
Wednesday, March 10, 2010



This topic is archived.

Back to support forum

Forum search