Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

attach a "filter view" to a button in google sheets

I am trying to toggle my preset filter views on and off without having to dig through the menus. I would like to attach them to a button, but google only lets me attach a script. I came up with the following script which works but is painfully slow:

function formFilter() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();

  for (var i=2; i <=numRows -1; i++) {
    var row =values[i];

    // Column value
    var myValue = row[6];

    // hide values that are not MOLFORM 
    if (myValue == "MOLFILL" || myValue =="MOLTEST" || myValue =="MOLKIT" || myValue =="MOLLEAD" ) {
     sheet.hideRows(i+1);
    }
  }
}

Please help me out with a better script!

like image 217
user3799246 Avatar asked Nov 11 '22 05:11

user3799246


1 Answers

There is not — yet — scripting abilities in GAS to manipulate Filters, either AutoFilters nor custom Filters…

Unfortunate since they are so useful.

like image 63
Antoine Beaubien Avatar answered Nov 28 '22 07:11

Antoine Beaubien