Skip to main content

Cell.Filter

Cell.Filter is an object type of the Spreadsheet module (Office.cell(iframe)). 6 methods.

Remarks​

Methods​

MethodDescription
applyFilter(colId, criteria)Applies filter criteria to the specified column.
clearFilter(colId)Clears the filter criteria.
create(range)Creates an AutoFilter.
getInfo()Returns the filter range, the criteria of each column, the number of rows hidden by the filter, and the sort state.
remove()Removes the AutoFilter.
sort(colId, order)Sorts the filter range by the specified column and keeps the sort state in the filter.

Method details​

applyFilter(colId, criteria)​

Applies filter criteria to the specified column. If criteria is null, the criteria of that column are cleared. If the header area is merged, specifying any column within the merged area applies the filter only to the first column of the merged area. A sheet filter must be created beforehand with create(), but for a table, applying criteria when there is no filter also creates the filter.

applyFilter(colId: number, criteria: object | null): Promise<void>;

Parameters

NameTypeDescription
colIdnumbertarget column. It is a 0-based offset from the first column of the filter range (0 is the first column). It uses the same coordinate system as columns[].colId of getInfo()
criteriaobject | nullfilter criteria to apply. It is one of the schemas FilterValuesCriteria, FilterCustomCriteria, FilterTop10Criteria, and FilterDynamicCriteria, depending on FilterType (see each typedef for the fields). If null, the criteria of that column are cleared

Returns

none

clearFilter(colId)​

Clears the filter criteria. If colId is specified, only that column is cleared. If omitted, all columns with criteria are cleared. The filter buttons remain. Does nothing if there are no criteria to clear or the table does not have a filter yet.

clearFilter(colId?: number): Promise<void>;

Parameters

NameTypeDescription
colId (optional)numbercolumn to clear. It is a 0-based offset from the first column of the filter range (0 is the first column). If omitted, all columns are cleared

Returns

none

create(range)​

Creates an AutoFilter. A sheet filter is created on the range specified by range. If range is omitted, the data region surrounding the current selection is used. A table filter ignores range and is created on the table range excluding the totals row. A filter cannot be created if the target already has one, or if range is omitted and the selection is a single empty cell.

create(range?: string | RangeCoords): Promise<void>;

Parameters

NameTypeDescription
range (optional)string | RangeCoordsrange to create the filter on. An A1 notation string is also accepted ("A1:B2", or "E10" for a single cell)

Returns

none

getInfo()​

Returns the filter range, the criteria of each column, the number of rows hidden by the filter, and the sort state. If no filter exists yet, only enabled is included, as false, and the other fields are omitted.

getInfo(): Promise<FilterInfo>;

Returns

Promise<FilterInfo>

remove()​

Removes the AutoFilter. The filter range and the column criteria are removed together.

remove(): Promise<void>;

Returns

none

sort(colId, order)​

Sorts the filter range by the specified column and keeps the sort state in the filter. If the header area is merged, specifying any column within the merged area sorts by the first column of the merged area. For a table, sorting also creates a filter if there is none, but a sheet does not create one automatically, so create() must be called first.

sort(colId: number, order: SortOrder): Promise<Filter>;

Parameters

NameTypeDescription
colIdnumbercolumn to sort by. It is a 0-based offset from the first column of the filter range (0 is the first column). It uses the same coordinate system as sort.colId of getInfo()
orderSortOrdersort order

Returns

Promise<Filter> - this Filter, so that calls can be chained