Home > Software engineering >  Google App Script - getFilter and getRange does not return desired filtered results
Google App Script - getFilter and getRange does not return desired filtered results

Time:12-03

I have a filter applied to a sheet. I want to return just the data from the filter and not the entire range of the sheet.

  const sheet = SpreadsheetApp.openById(SHEET_ID).getSheetByName(SHEET_NAME)

  const filter = sheet.getFilter();
  // This returns the entire sheet's range rather than the filtered range.
  const range = filter.getRange().getValues();

Based on the code above, why aren't I getting the desired behaviour according to docs from Google?

CodePudding user response:

You can get just the values the active filter displays by removing the values in the data that are in rows where isRowHiddenByFilter(rowPosition) returns true.

That said, using JavaScript's Array.filter() would offer much better performance than making multiple API calls to find which rows are hidden.

CodePudding user response:

I had a similar issue with returning filtered values and realized it is the most convenient to make a code that will skip FilterCriteriaBuilder class with functions.

Maybe you can find your solution here.

https://github.com/NikolaPlusEqual/GoogleAppsScriptFilters/blob/main/Functions

Just copy entire Functions file code and call desired function.

  • Related