sortOrder([column], [new_column_order], [order])

Class: Table.

Description:

Gets or sets current sort state of the table rows by specifying column and order. Does not sort by columns that are set to be not sortable.

See usage examples below.

Parameters:

Name Type Default Description

[column]

number | null | undefined

Column index to sort by, or null to clear sorting al onn columns. Omit or leave undefined to get current sort state.

[new_column_order]

boolean

false

Whether the given column index should be interpreted as a new column order (useful if columns were reordered).

[order]

Table.SortOrder

Table.SortOrder.None

One of: Table.SortOrder.None (default), Table.SortOrder.Ascending, Table.SortOrder.Descending.

Returns:

Returns this Table object for method chaining when settings a sort, otherwise returns current sort order as {column:number, order:Table.SortOrder} or null when table rows are not sorted.

Type: Table | object | null

Examples:

Setting a sort column and order:

// Sorts rows by column 2 in descending order
table.sortOrder(2, false, Table.SortOrder.Descending);

// Resets sorting by column 2 while still sorting by previously sorted columns (if any)
table.sortOrder(2, false, Table.SortOrder.None);

// Resets row sorting for all columns. Rows become unsorted.
table.sortOrder(null);

Getting current sort state:

let sorting = table.sortOrder();
// returns `null` if there was no sorting applied to the table
// or object like {column: 2, order: Table.SortOrder.Descending} if column 2 is currently sorted.
// Returned `column` index is the original column index (remain same even after after columns were reordered).

Also See: