Class Filter Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The Filter class is used to modify existing filters on Grid sheets.
To use the Filter class, you must first access the filter using Range.getFilter() or Sheet.getFilter().
Common uses of the Filter class include removing a filter and getting the range the filter applies to.
The Filter class provides methods for managing filter criteria on columns and sorting the filtered range.
Use this class to modify existing filters onGrid sheets, the default type ofsheet. Grid sheets are regular sheets with data that aren't connected to a database.
If a filter doesn’t exist on the sheet yet, create one usingRange.createFilter().
To use this class, you must first access the grid sheet filter usingRange.getFilter() orSheet.getFilter().
Common uses
Remove a filter
The below sample gets the filter on the active sheet and removes it.constss=SpreadsheetApp.getActiveSheet();constfilter=ss.getFilter();// Removes the filter from the active sheet.filter.remove();
Get the range that the filter applies to
The below sample gets the filter on the active sheet, then uses thegetRange() method fromthis class to log the range that the filter applies to.constss=SpreadsheetApp.getActiveSheet();// Gets the existing filter on the active sheet.constfilter=ss.getFilter();// Logs the range that the filter applies to in A1 notation.console.log(filter.getRange().getA1Notation());
Methods
| Method | Return type | Brief description |
|---|---|---|
get | Filter | Gets the filter criteria on the specified column, ornull if the column doesn't havefilter criteria applied to it. |
get | Range | Gets the range this filter applies to. |
remove() | void | Removes this filter. |
remove | Filter | Removes the filter criteria from the specified column. |
set | Filter | Sets the filter criteria on the specified column. |
sort(columnPosition, ascending) | Filter | Sorts the filtered range by the specified column, excluding the first row (the header row) inthe range this filter applies to. |
Detailed documentation
getColumnFilterCriteria(columnPosition)
Gets the filter criteria on the specified column, ornull if the column doesn't havefilter criteria applied to it.
To get more details about the filter criteria, chain this method with methods from theFilter class.
constss=SpreadsheetApp.getActiveSheet();constfilter=ss.getFilter();// Gets the filter criteria applied to column B of the active sheet// and logs the hidden values.constfilterCriteria=filter.getColumnFilterCriteria(2).getHiddenValues();console.log(filterCriteria);
Parameters
| Name | Type | Description |
|---|---|---|
column | Integer | The 1-indexed position of the column. For example, column B's index is 2. |
Return
Filter — The filter criteria.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
getRange()
Gets the range this filter applies to.
// Gets the existing filter on the active sheet.constss=SpreadsheetApp.getActiveSheet();constfilter=ss.getFilter();// Logs the range that the filter applies to in A1 notation.console.log(filter.getRange().getA1Notation());
Return
Range — The filter's range. To get the range in A1 notation, chain this method withRange.getA1Notation().
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
remove()
Removes this filter.
// Removes the filter from the active sheet.constss=SpreadsheetApp.getActiveSheet();constfilter=ss.getFilter();filter.remove();
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
removeColumnFilterCriteria(columnPosition)
Removes the filter criteria from the specified column.
// Removes the filter criteria from column B.constss=SpreadsheetApp.getActiveSheet();constfilter=ss.getFilter();filter.removeColumnFilterCriteria(2);
Parameters
| Name | Type | Description |
|---|---|---|
column | Integer | The 1-indexed position of the column. For example, column B's index is 2. |
Return
Filter — The filter, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
setColumnFilterCriteria(columnPosition, filterCriteria)
Sets the filter criteria on the specified column. First, create the filter criteria builderusingSpreadsheet. Then add criteria to the builderusing theFilter class. After you've built your criteria, set it as thefilter parameter for this method.
constss=SpreadsheetApp.getActiveSheet();constfilter=ss.getFilter();// Builds the filter criteria to use as a parameter for setColumnFilterCriteria.constcriteria=SpreadsheetApp.newFilterCriteria().setHiddenValues(['Hello','World']).build();// Sets the filter criteria for column C.filter.setColumnFilterCriteria(3,criteria);
Parameters
| Name | Type | Description |
|---|---|---|
column | Integer | The 1-indexed position of the column. For example, column B's index is 2. |
filter | Filter | The filter criteria to set. If you set the criteria tonull, it removes filter criteria from the specified column. You can also useremove. |
Return
Filter — The filter, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
sort(columnPosition, ascending)
Sorts the filtered range by the specified column, excluding the first row (the header row) inthe range this filter applies to.
// Gets the existing filter and sorts it by column B in ascending order.constss=SpreadsheetApp.getActiveSheet();constfilter=ss.getFilter();filter.sort(2,true);
Parameters
| Name | Type | Description |
|---|---|---|
column | Integer | The 1-indexed position of the column. For example, column B's index is 2. |
ascending | Boolean | Iftrue, sorts the filtered range in ascending order; iffalse, sorts the filtered range in descending order. |
Return
Filter — The filter, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.