Cell.Filter
Cell.Filter is an object type of the Spreadsheet module (Office.cell(iframe)). 6 methods.
Remarks
- Module: Spreadsheet ·
Office.cell(iframe)· namespaceCell - Obtained from:
Worksheet.getFilter(),Table.getFilter() - Every method returns a
Promise; signatures use TypeScript notation.
Methods
| Method | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
colId | number | target 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() |
criteria | object | null | filter 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
| Name | Type | Description |
|---|---|---|
colId (optional) | number | column 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
| Name | Type | Description |
|---|---|---|
range (optional) | string | RangeCoords | range 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
| Name | Type | Description |
|---|---|---|
colId | number | column 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() |
order | SortOrder | sort order |
Returns
Promise<Filter> - this Filter, so that calls can be chained