3.2.0

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
March 9,
Alex posted a simple example here (that is also valid for csv data model):
http://www.activewidgets.com/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(text, column){

    var i, rows = [], 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=0; i<max; i++){   /////////  FOR ARRAY DATA MODEL USE: max2
        if (obj.getCellValue(column, i).indexOf(text)> -1 ){
            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 i, rows = [], max = table.getCount(); /////////  FOR ARRAY DATA MODEL USE: (in new line) max = gridVar.getRowCount(); 

var samecolfound = false;

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

if(filtersrunning.length > 0 ){ 
for(var aa=0 ; aa<filtersrunning.length ; aa++){ 
if(filtersrunning[aa][0] == column){samecolfound = true } 
}  
for(var z=0 ; 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 == 0 ){
obj.setRowCount(max); /////////  FOR ARRAY DATA MODEL USE: max2
obj.setRowIndices(''); 
//Lab.setControlText("FOUND: " + max);
obj.setRowCount(rows.length); 
}

if(filters.length > 0 ){
 for (rw=0; rw<max; rw++){    /////////  FOR ARRAY DATA MODEL USE: max2
 var found =0;
  for (Xcol=0; Xcol<filters.length; Xcol++){ 
   if ( obj.getCellText(filters[Xcol][0], rw).toUpperCase().indexOf(filters[Xcol][1]) >-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...
http://www.activewidgets.com/javascript.forum.22570.11/need-help-with-filter-based.html
and here respectively:
http://www.activewidgets.com/javascript.forum.25833.28/column-header-dropdownbox-filter-example.html
HTH
Carlos
March 10,

This topic is archived.

See also:


Back to support forum