Class SortSpec
Stay organized with collections
Save and categorize content based on your preferences.
SortSpec
The sorting specification.
Detailed documentation
getBackgroundColor()
Returns the background color used for sorting, or null
if absent.
Return
Color
— The background color.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceColumn()
Gets the data source column the sort spec acts on. Returns null
if this sort spec is
not acting on a data source column.
Return
DataSourceColumn
— The data source column the sort spec acts on.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDimensionIndex()
Returns the dimension index or null
if not linked to a local filter.
Return
Integer
— The dimension index.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getForegroundColor()
Returns the foreground color used for sorting, or null
if absent.
Return
Color
— The foreground color.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSortOrder()
Returns the sort order.
Return
SortOrder
— The sort order.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isAscending()
Returns whether the sort order is ascending.
Return
Boolean
— true
if the sort order is ascending, or false
otherwise.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.
[null,null,["Last updated 2024-12-02 UTC."],[[["\u003cp\u003e\u003ccode\u003eSortSpec\u003c/code\u003e defines the specifications for sorting data, such as sort order, colors, and the data source.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to retrieve information about the sort specification, including background and foreground colors, sort order, and the data source column being used.\u003c/p\u003e\n"],["\u003cp\u003eYou can determine if the sort order is ascending using the \u003ccode\u003eisAscending()\u003c/code\u003e method and obtain the dimension index with \u003ccode\u003egetDimensionIndex()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAll methods within \u003ccode\u003eSortSpec\u003c/code\u003e require authorization with specific scopes related to spreadsheet access.\u003c/p\u003e\n"]]],["SortSpec defines the criteria for sorting data. Key actions include retrieving the background and foreground colors used in sorting, if any. It fetches the data source column being sorted, or returns null if not present. It can retrieve the dimension index if linked to a filter. The sort order itself, along with whether the sorting is ascending, can also be obtained using the methods `getSortOrder()` and `isAscending()` respectively.\n"],null,["# Class SortSpec\n\nSortSpec\n\nThe sorting specification. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------|---------------------------------------------------------------------------|------------------------------------------------------------------------|\n| [getBackgroundColor()](#getBackgroundColor()) | [Color](/apps-script/reference/spreadsheet/color) | Returns the background color used for sorting, or `null` if absent. |\n| [getDataSourceColumn()](#getDataSourceColumn()) | [DataSourceColumn](/apps-script/reference/spreadsheet/data-source-column) | Gets the data source column the sort spec acts on. |\n| [getDimensionIndex()](#getDimensionIndex()) | `Integer` | Returns the dimension index or `null` if not linked to a local filter. |\n| [getForegroundColor()](#getForegroundColor()) | [Color](/apps-script/reference/spreadsheet/color) | Returns the foreground color used for sorting, or `null` if absent. |\n| [getSortOrder()](#getSortOrder()) | [SortOrder](/apps-script/reference/spreadsheet/sort-order) | Returns the sort order. |\n| [isAscending()](#isAscending()) | `Boolean` | Returns whether the sort order is ascending. |\n\nDetailed documentation\n----------------------\n\n### `get``Background``Color()`\n\nReturns the background color used for sorting, or `null` if absent.\n\n#### Return\n\n\n[Color](/apps-script/reference/spreadsheet/color) --- The background color.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Data``Source``Column()`\n\nGets the data source column the sort spec acts on. Returns `null` if this sort spec is\nnot acting on a data source column.\n\n#### Return\n\n\n[DataSourceColumn](/apps-script/reference/spreadsheet/data-source-column) --- The data source column the sort spec acts on.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Dimension``Index()`\n\nReturns the dimension index or `null` if not linked to a local filter.\n\n#### Return\n\n\n`Integer` --- The dimension index.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Foreground``Color()`\n\nReturns the foreground color used for sorting, or `null` if absent.\n\n#### Return\n\n\n[Color](/apps-script/reference/spreadsheet/color) --- The foreground color.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Sort``Order()`\n\nReturns the sort order.\n\n#### Return\n\n\n[SortOrder](/apps-script/reference/spreadsheet/sort-order) --- The sort order.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `is``Ascending()`\n\nReturns whether the sort order is ascending.\n\n#### Return\n\n\n`Boolean` --- `true` if the sort order is ascending, or `false` otherwise.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`"]]