I’m looking for a faster way to switch between my custom filter views in Google Sheets. Right now I have to go through menus to do this. It would be great if I could just click a button instead.
I tried making a script to do this but it’s super slow:
function applyCustomFilter() {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getActiveSheet();
let data = sheet.getDataRange().getValues();
for (let i = 1; i < data.length; i++) {
if (!['TYPE1', 'TYPE2', 'TYPE3', 'TYPE4'].includes(data[i][6])) {
sheet.hideRows(i + 1);
}
}
}
Does anyone know a quicker way to toggle filter views on and off with buttons? The current script works but takes forever to run. Any tips to speed this up would be awesome. Thanks!
I’ve discovered that using Google Sheets’ built-in FILTER function can offer a significant speed improvement over scripts that loop through rows. Instead of hiding rows manually, you can set up separate sheets that display only the relevant data by referencing your source sheet with the FILTER function. This method updates automatically and is almost instantaneous compared to scripts. While it’s not exactly a button to toggle views, navigating between these dedicated sheets can streamline your workflow and reduce delays considerably.
I’ve been tackling the same issue and switched to using built-in filter views for a more efficient experience. Instead of scripting to hide rows, create a custom filter view for each data set via Data > Create a filter view and set your criteria accordingly. A shortcut like Alt+D and then V can quickly open the filter view menu to pick your view. If you need a button approach, a script that applies the filter view by its ID is significantly faster than looping over rows. Hope this helps.
hey emma! i’ve found that using named ranges + data validation can be a quick fix. set up named ranges for each filter view, then use data validation to create a dropdown. pair it with FILTER() to show only matching data. it’s way faster than scripting and you can switch views with a single click. lemme know if u need more details!