Search code examples
google-sheetsgoogle-apps-script

isRowHiddenByFilter(rowPosition) not returning true while the row is hidden


I have a table that has a filter on col2. I want to get the selected values and print them on a sidebar (html), so the user can copy the ids.

Here is my table setup : I have my filter, and the 32 first rows are invisible (such as other rows in the rest of the table).

table

I have this script.gs :

function myFunction() {
  const sheet = SpreadsheetApp.getActiveSheet();

  // return "sheet 10, false"
  Logger.log(sheet.getName(), sheet.isRowHiddenByFilter(4))
}

Now, my problem is that the sheet.isRowHiddenByFilter(rowIndex) always returns false, while the row n°4 is hidden by my filter.

The documentation does not add more info : https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet?hl=fr#isrowhiddenbyfilterrowposition

I couldn't find another script using “isRowHiddenByFilter”.

The code is pretty simple and there are no deprecated tags on the function, so it should work properly. Since I'm using the new table system, I don't know if it's the source of the issue.


Solution

  • isRowHiddenByFilter only works with filters:

    Toolbar snapshot red circling the filter button.

    This method doesn't work for filter views and the new group by view.

    The workaround is activating the filter from the Google Sheets toolbar or using the dropdown menu in the column header.

    Sheet showing a table with a filter hidding row 2

    function myFunction() {
      const isHidden = SpreadsheetApp.getActiveSheet().isRowHiddenByFilter(2);
      Logger.log(isHidden);
    }
    
    /**
     * When running the above function it shows true when row 2  
     * is hidden by a filter and false when hidden by a filter view
     */