Excel.TableSort class

Manages sorting operations on Table objects.

[ API set: ExcelApi 1.2 ]

Extends
OfficeExtension.ClientObject

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

fields

Represents the current conditions used to last sort the table. Read-only.

[ API set: ExcelApi 1.2 ]

matchCase

Represents whether the casing impacted the last sort of the table. Read-only.

[ API set: ExcelApi 1.2 ]

method

Represents Chinese character ordering method last used to sort the table. Read-only.

[ API set: ExcelApi 1.2 ]

Methods

apply(fields, matchCase, method)

Perform a sort operation.

[ API set: ExcelApi 1.2 ]

apply(fields, matchCase, methodString)

Perform a sort operation.

[ API set: ExcelApi 1.2 ]

clear()

Clears the sorting that is currently on the table. While this doesn't modify the table's ordering, it clears the state of the header buttons.

[ API set: ExcelApi 1.2 ]

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

reapply()

Reapplies the current sorting parameters to the table.

[ API set: ExcelApi 1.2 ]

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.TableSort object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.TableSortData) that contains shallow copies of any loaded child properties from the original object.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

fields

Represents the current conditions used to last sort the table. Read-only.

[ API set: ExcelApi 1.2 ]

readonly fields: Excel.SortField[];

Property Value

matchCase

Represents whether the casing impacted the last sort of the table. Read-only.

[ API set: ExcelApi 1.2 ]

readonly matchCase: boolean;

Property Value

boolean

method

Represents Chinese character ordering method last used to sort the table. Read-only.

[ API set: ExcelApi 1.2 ]

readonly method: Excel.SortMethod | "PinYin" | "StrokeCount";

Property Value

Excel.SortMethod | "PinYin" | "StrokeCount"

Method Details

apply(fields, matchCase, method)

Perform a sort operation.

[ API set: ExcelApi 1.2 ]

apply(fields: Excel.SortField[], matchCase?: boolean, method?: Excel.SortMethod): void;

Parameters

fields
Excel.SortField[]

The list of conditions to sort on.

matchCase
boolean

Optional. Whether to have the casing impact string ordering.

method
Excel.SortMethod

Optional. The ordering method used for Chinese characters.

Returns

void

Examples

Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var table = ctx.workbook.tables.getItem(tableName);
    table.sort.apply([ 
            {
                key: 2,
                ascending: true
            },
        ], true);
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

apply(fields, matchCase, methodString)

Perform a sort operation.

[ API set: ExcelApi 1.2 ]

apply(fields: Excel.SortField[], matchCase?: boolean, methodString?: "PinYin" | "StrokeCount"): void;

Parameters

fields
Excel.SortField[]

The list of conditions to sort on.

matchCase
boolean

Optional. Whether to have the casing impact string ordering.

methodString
"PinYin" | "StrokeCount"

Optional. The ordering method used for Chinese characters.

Returns

void

clear()

Clears the sorting that is currently on the table. While this doesn't modify the table's ordering, it clears the state of the header buttons.

[ API set: ExcelApi 1.2 ]

clear(): void;

Returns

void

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: Excel.Interfaces.TableSortLoadOptions): Excel.TableSort;

Parameters

options
Excel.Interfaces.TableSortLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.TableSort;

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.TableSort;

Parameters

propertyNamesAndPaths
{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

reapply()

Reapplies the current sorting parameters to the table.

[ API set: ExcelApi 1.2 ]

reapply(): void;

Returns

void

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.TableSort object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.TableSortData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.TableSortData;

Returns