Reputation: 31
I'm looking to create almost a drop-down feature in Google Sheets. I was hoping to have arrows set that could potentially collapse rows when clicked.
It would be amazing if I could get it so each main "title" row has an arrow, that would cause the rows to either hide/unhide.
Since only the titles would be written in column A, I was thinking it might be possibly for a script to recognize the blank cells in between two filled ones?
So far I only have this, which is basically useless:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Hides the first three rows
sheet.hideRows(1, 3);
In a perfect world, the spreadsheet would look something like this, with the functionality to collapse the rows with the click of the arrow.
https://docs.google.com/spreadsheets/d/1-oGawFoPXjdHvadxXsSFxuZWWdOxN9ZgbvS10jelWZY/edit?usp=sharing
Not sure if this is possible, but if there is any hope/ideas I'd love to hear them.
Upvotes: 1
Views: 5128
Reputation: 64032
function onEdit(e) {
const sh=e.range.getSheet();
const shts=['Sheet13'];
if(shts.indexOf(sh.getName())!=-1 && e.range.columnStart==1 && e.value=="TRUE") {
e.range.setValue("FALSE");
sh.hideRows(Number(e.range.rowStart));
e.source.toast('Row ' + e.range.rowStart + ' has been hidden.');
}
}
Animation:
Upvotes: 3
Reputation: 6544
Instead, have you considered using the group row facility? You can just group and ungroup the rows to show/hide them.
I have added the same in the spreadsheet that you have shared.
Upvotes: 1