How to adjust google sheet view depending on variable? -
i have spreadsheet following script adjusts view rows according variable:
function conditionalhiderow() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheetbyname("form responses 1"); var maxrows = sheet.getmaxrows() (var = 0; < maxrows; ++i) { if (sheet.getrange(maxrows-i,4).getvalue() == "var1" ) { sheet.hiderows(maxrows-i,1) } else { sheet.showrows(maxrows-i,1) } } }
i want pass variable in page adjusts view: example
- if pass var1 in url example, rows containing var1 shown, others not
- if pass var2 in url example, rows containing var2 shown, others not
etc
i have tried function doget(e) var viewmode = e.parameter.view doesn't seem work when passing ....?view = "a"
to pass "a" doget()
in url query ...?view=a
; no need in apostrophes.
sample
function doget(e){ var parameter = e.parameter; if(parameter.view){ //check off view type passed conditionalhiderow(parater.view); }; } function conditionalhiderow(condition){ var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheetbyname("form responses 1"); var maxrows = sheet.getdatarange().getheight(); (var = 0; < maxrows; ++i) { if (sheet.getrange(maxrows-i,4).getvalue() == condition ) { sheet.hiderows(maxrows-i,1); } else { sheet.showrows(maxrows-i,1); }; } }
this off topic, getdatarange().getheight()
experience better use, since getmaxrows()
return total number of rows, if empty.
by default there 1000 empty rows, , though don't have data there, still loop through it. getdatarange().getheight()
give number of last row piece of data appears.
also, curious, why looping backwards through rows?
Comments
Post a Comment