Yaniv Aflalo
Yaniv Aflalo

Reputation: 249

restrict number of filter results on Google Sheets with Google Apps Script

I want the user to be able to rstrict the number of shown results in a table filtered per the user's decision.

The user enters the max results to show in cell A1. The table (with or without fitered rows) is from row 2 to the last row (row 2 is headers).

Currently, I use .showRows() as follows: sheet.showRows(3,sheet.getRange('A1').getValue());

The issue with this is that it takes also the filtered out rows into consideration.

For example, if the user want to see 5 result and rows 4-6 are filtred out- the spreadsheet will show only 2 rows (3 and 7), when it is supposed to show 5 rows (3 and 7-10).

How can it be achieved?

Upvotes: 0

Views: 389

Answers (1)

doubleunary
doubleunary

Reputation: 18784

Iterate rows in the sheet and use Sheet.isRowHiddenByFilter() to count rows that are not hidden until you have found a sufficient number of unfiltered rows, then hide the rows below that with Sheet.hideRows().

Upvotes: 3

Related Questions