# FPivotTable

> Language fallback: requested `ko-KR`; content is `en-US`.

- Human documentation: [https://docs.univer.ai/ko-KR/reference/facade/pivot-table](https://docs.univer.ai/ko-KR/reference/facade/pivot-table)

- Agent Markdown: [https://docs.univer.ai/ko-KR/reference/facade/pivot-table.md](https://docs.univer.ai/ko-KR/reference/facade/pivot-table.md)

- Requested language: `ko-KR`

- Content language: `en-US`

- Documentation version: `1.0.4`

- Source: [facade/pivot-table.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/pivot-table.mdx)

---

The facade class for the pivot table.Which uses to setting the pivot table fields configs.

## Access

Access through:

* [`FWorkbook.addPivotTable()`](https://docs.univer.ai/ko-KR/reference/facade/workbook.md#addpivottable)
* [`FWorkbook.getPivotTableByCell()`](https://docs.univer.ai/ko-KR/reference/facade/workbook.md#getpivottablebycell)
* [`FWorkbook.getPivotTableById()`](https://docs.univer.ai/ko-KR/reference/facade/workbook.md#getpivottablebyid)
* [`FWorksheet.getPivotTableByCell()`](https://docs.univer.ai/ko-KR/reference/facade/worksheet.md#getpivottablebycell)
* [`FSheetPivotChart.getPivotTable()`](https://docs.univer.ai/ko-KR/reference/facade/sheet-pivot-chart.md#getpivottable)

## Setup

Register [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) or a preset that includes it. In plugin mode, import `@univerjs-pro/sheets-pivot/facade`. Additional methods below require their listed plugin packages. See [Facade setup](https://docs.univer.ai/ko-KR/guides/sheets/getting-started/facade.md).

## `@univerjs-pro/sheets-pivot`

### `FPivotTable.addField`

Add a pivot field to the pivot table.

```typescript
addField(dataFieldIdOrIndex: string | number, fieldArea: PivotTableFiledAreaEnum, index: number): Promise<boolean>
```

**Parameters**

* `dataFieldIdOrIndex` — Required. The data field id.
* `fieldArea` — Required. The area of the field.
* `index` — Required. The index of the field in the target area.

**Returns**

Whether the pivot field is added successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)

if (fPivotTable) {
  // 1 means the source range index , 0 means the index in the target area.
  await fPivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`PivotTableFiledAreaEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.clearLabelSort`

Clear the pivot table label sort. The field returns to the configured default label ordering.

```typescript
clearLabelSort(tableFieldId: string): Promise<boolean>
```

**Parameters**

* `tableFieldId` — Required. The field id of the sort.

**Returns**

Whether the pivot table label sort is cleared successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fPivotTable = fWorksheet.getPivotTableByCell(0, 8)
if (!fPivotTable) throw new Error('fPivotTable is not available')
const rowIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
if (rowIds.length > 0) {
  await fPivotTable.clearLabelSort(rowIds[0])
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.clearValueFilter`

Clear the value filter of the pivot table field through command.

```typescript
clearValueFilter(fieldId: string): Promise<boolean>
```

**Parameters**

* `fieldId` — Required. The field id of the value filter.

**Returns**

Whether the value filter is cleared successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
const rowId = fPivotTable?.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)[0]
if (fPivotTable && rowId) {
  await fPivotTable.clearValueFilter(rowId)
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.drillDown`

Drill down a pivot value cell through command and create a sheet with the related source records.

```typescript
drillDown(row: number, col: number): Promise<boolean>
```

**Parameters**

* `row` — Required. The row index of the pivot value cell.
* `col` — Required. The column index of the pivot value cell.

**Returns**

Whether the drill down sheet is created successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
await fPivotTable?.drillDown(5, 10)
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getConfig`

Get the pivot table config by the pivot table id.

```typescript
getConfig(): Nullable<IPivotTableConfig>
```

**Returns**

The pivot table config or undefined.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
const pivotTableConfig = fPivotTable.getConfig()
const { targetCellInfo, sourceRangeInfo, isEmpty } = pivotTableConfig
console.log(targetCellInfo, sourceRangeInfo, isEmpty)
```

**Types:** [`IPivotTableConfig`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/const/type.d.ts) · [`Nullable`](https://unpkg.com/@univerjs/core/lib/types/shared/types.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getFieldIdsByArea`

Get the field ids by the field area.

```typescript
getFieldIdsByArea(fieldArea: PivotTableFiledAreaEnum): string[]
```

**Parameters**

* `fieldArea` — Required. The area of the field.

**Returns**

The field ids in the target area.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
const fieldIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
console.log(fieldIds)
```

**Types:** [`PivotTableFiledAreaEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getFieldSetting`

Get the pivot table field setting by the field id.

```typescript
getFieldSetting(fieldId: string): IPivotTableValueFieldJSON | IPivotTableLabelFieldJSON | undefined
```

**Parameters**

* `fieldId` — Required. The table field id.

**Returns**

The field setting.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
const fieldId = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)[0]
if (filedId) {
  const fieldSetting = fPivotTable.getFieldSetting(fieldId)
}
```

**Types:** [`IPivotTableValueFieldJSON`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/json-types.d.ts) · [`IPivotTableLabelFieldJSON`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/json-types.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getId`

Get the pivot table id.

```typescript
getId(): string
```

**Returns**

The pivot table id.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
const pivotTableId = fPivotTable?.getId()
console.log(pivotTableId)
```

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getLayout`

Get the pivot table layout type.

```typescript
getLayout(): PivotLayoutTypeEnum | undefined
```

**Returns**

The layout type, or undefined if the pivot table no longer exists.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fSheet = fWorkbook.getActiveSheet()
const subUnitId = fSheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
const layout = fPivotTable?.getLayout()
console.log(layout === univerAPI.Enum.PivotLayoutTypeEnum.tabular)
```

**Types:** [`PivotLayoutTypeEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getOptions`

Get the display options of the pivot table.

```typescript
getOptions(): IPivotTableOptions | undefined
```

**Returns**

The display options or undefined if the pivot table no longer exists.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
const options = fPivotTable?.getOptions()
console.log(options?.showRowGrandTotal)
```

**Types:** [`IPivotTableOptions`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/layout-type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getPivotTableId`

Get the pivot table id.

```typescript
getPivotTableId(): string
```

**Returns**

The pivot table id.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
const pivotTableId = fPivotTable.getPivotTableId()
console.log(pivotTableId)
```

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getPivotTableMatrixInfo`

Get the pivot table matrix cache generated by the last render.

```typescript
getPivotTableMatrixInfo(): IPivotTableMatrixInfo | undefined
```

**Returns**

The matrix cache or undefined if the pivot table has not rendered.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
const matrixInfo = fPivotTable?.getPivotTableMatrixInfo()
console.log(matrixInfo?.matrix)
```

**Types:** [`IPivotTableMatrixInfo`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/const/type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getPivotTableRangeInfo`

Get the pivot table range info in worksheet.

```typescript
getPivotTableRangeInfo(): IRange[] | undefined
```

**Returns**

The pivot table range list.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const pivotTableRangeInfo = fPivotTable.getPivotTableRangeInfo()
  console.log(pivotTableRangeInfo)
}
```

**Types:** [`IRange`](https://docs.univer.ai/ko-KR/reference/types/range.md)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getShowDataAs`

Get the Show Values As configuration of a pivot table value field.

```typescript
getShowDataAs(fieldId: string): IPivotTableShowDataAsInfo | undefined
```

**Parameters**

* `fieldId` — Required. The value field id.

**Returns**

The Show Values As configuration, or `undefined` when the field is not a value field.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fPivotTable = fWorksheet.getPivotTableByCell(0, 8)
if (!fPivotTable) throw new Error('fPivotTable is not available')
const valueId = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)[0]
if (valueId) {
  const showDataAs = fPivotTable.getShowDataAs(valueId)
  console.log(showDataAs)
}
```

**Types:** [`IPivotTableShowDataAsInfo`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/interface.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getSourceFieldsInfo`

Get the pivot table field info list.

```typescript
getSourceFieldsInfo(): IPivotTableDataFieldInfo[]
```

**Returns**

The field info list.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const fieldInfos = fPivotTable.getSourceFieldsInfo()
  console.log(fieldInfos)
}
```

**Types:** [`IPivotTableDataFieldInfo`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getSourceRangeInfo`

Get the source range info of the pivot table.

```typescript
getSourceRangeInfo(): IUnitRangeNameWithSubUnitId | undefined
```

**Returns**

The source range info or undefined if the pivot table no longer exists.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
const sourceRangeInfo = fPivotTable?.getSourceRangeInfo()
console.log(sourceRangeInfo?.range)
```

**Types:** [`IUnitRangeNameWithSubUnitId`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/const/type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getTargetCellInfo`

Get the target cell info of the pivot table.

```typescript
getTargetCellInfo(): IPivotTableConfig['targetCellInfo'] | undefined
```

**Returns**

The target cell info or undefined if the pivot table no longer exists.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
const targetCellInfo = fPivotTable?.getTargetCellInfo()
console.log(targetCellInfo?.row, targetCellInfo?.col)
```

**Types:** [`IPivotTableConfig`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/const/type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getValueFilter`

Get the value filter owned by a row or column field.

```typescript
getValueFilter(fieldId: string): IPivotTableValueFilter | undefined
```

**Parameters**

* `fieldId` — Required. The row or column field id.

**Returns**

A copy of the value filter, or `undefined` when the field has no value filter.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const rowIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
  const valueFilter = fPivotTable.getValueFilter(rowIds[0])
  console.log(valueFilter)
}
```

**Types:** [`IPivotTableValueFilter`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/interface.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.getValueFilters`

Get all value filters in their evaluation order. A later rule evaluates only the items retained by earlier rules.

```typescript
getValueFilters(): IValueFilterInfoItem[]
```

**Returns**

Copies of the ordered value-filter rules.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const valueFilters = fPivotTable.getValueFilters()
  console.log(valueFilters)
}
```

**Types:** [`IValueFilterInfoItem`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/interface.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.move`

Move the pivot table to the target cell.

```typescript
move(sheetName: string, row: number, col: number): Promise<boolean>
```

**Parameters**

* `sheetName` — Required. The target sheet name.
* `row` — Required. The target row index.
* `col` — Required. The target column index.

**Returns**

Whether the pivot table is moved successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subSheetName = fWorksheet.getSheetName()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  // move pivot table to row:100, col:1
  await fPivotTable.move(subSheetName, 100, 1)
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.remove`

Remove a pivot table from the workbook by pivot table id

```typescript
remove(): Promise<boolean>
```

**Returns**

Whether the pivot table is removed successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)

if (fPivotTable) {
  fPivotTable.remove()
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.removeField`

Remove a pivot field from the pivot table

```typescript
removeField(fieldIds: string[]): Promise<boolean>
```

**Parameters**

* `fieldIds` — Required. The deleted field ids.

**Returns**

Whether the pivot field is removed successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const rowIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
  if (rowIds.length > 0) {
    // remove all field in row.
    await fPivotTable.removeField(rowIds)
  }
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.renameField`

Rename the pivot table field.

```typescript
renameField(fieldId: string, name: string): Promise<boolean>
```

**Parameters**

* `fieldId` — Required. The field id.
* `name` — Required. The new name of the field.

**Returns**

Whether the pivot table field is renamed successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const valueIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)
  if (valueIds.length > 0) {
    await fPivotTable.renameField(valueIds[0], 'newName')
  }
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.reset`

Clear the fields by provided field area or clear all fields.

```typescript
reset(resetArea?: PivotTableFiledAreaEnum): Promise<boolean>
```

**Parameters**

* `resetArea` — Optional. The area of the field to reset or undefined to reset all fields.

**Returns**

Whether the pivot table fields are reset successfully.

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`PivotTableFiledAreaEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.resetShowDataAs`

Reset the Show Values As configuration of a pivot table value field to the normal calculation.

```typescript
resetShowDataAs(fieldId: string): Promise<boolean>
```

**Parameters**

* `fieldId` — Required. The value field id.

**Returns**

Whether the Show Values As configuration is reset successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fPivotTable = fWorksheet.getPivotTableByCell(0, 8)
if (!fPivotTable) throw new Error('fPivotTable is not available')
const valueId = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)[0]
if (valueId) {
  await fPivotTable.resetShowDataAs(valueId)
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setCellCollapse`

Collapse or expand a pivot table item by the cell position through command.

```typescript
setCellCollapse(row: number, col: number, collapse: boolean): Promise<boolean>
```

**Parameters**

* `row` — Required. The row index of the pivot item cell.
* `col` — Required. The column index of the pivot item cell.
* `collapse` — Required. Whether to collapse the pivot item. True means collapse, false means expand.

**Returns**

Whether the pivot item collapse state is updated successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
// the cell must be a cell has collapse or expand button, otherwise the command will fail, and the cell (2,8) is just an example, you can pass any cell in the pivot table which has collapse or expand button.
await fPivotTable?.setCellCollapse(2, 8, true)
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setDateGroupType`

Set the date group type for the date group field.

```typescript
setDateGroupType(tableFieldId: string, dateType: PivotDateGroupFieldDateTypeEnum): Promise<boolean>
```

**Parameters**

* `tableFieldId` — Required. The field id of the group label field.
* `dateType` — Required. The date group type.

**Returns**

Whether the date group type is set successfully.

**Examples**

```ts
// To use this demo, you need to build a pivot table first, and make sure that the entire column in the pivot table source data is a date,
// and drag the date dimension to the row or column
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const pivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 0)
// Here we assume that the field index of the date type is 0
await pivotTable.addField(0, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)
const rowIds = pivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
if (rowIds.length > 0) {
  // Because the index is added to the position of 0 above, the index of the automatically derived date grouping dimension is 1
  await pivotTable.setDateGroupType(
    rowIds[1],
    univerAPI.Enum.PivotDateGroupFieldDateTypeEnum.YearMonthDate,
  )
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`PivotDateGroupFieldDateTypeEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setFieldsConfig`

Set the pivot table fields config.It will add fields to the pivot table from provided config.Before setting the fields config, you should ensure the pivot table is empty to avoid the conflict.

```typescript
setFieldsConfig(config: IPivotTableConfig['fieldsConfig']): Promise<boolean>
```

**Parameters**

* `config` — Required. The pivot table fields config.

**Returns**

Whether the pivot table fields config is set successfully.

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IPivotTableConfig`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/const/type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setFieldSetting`

Set the pivot table field display name, number format, subtotal type, or Show Values As configuration through command.

```typescript
setFieldSetting(tableFieldId: string, setting: IPivotTableFieldSettingOptions): Promise<boolean>
```

**Parameters**

* `tableFieldId` — Required. The pivot table field id.
* `setting` — Required. The field setting options.

**Returns**

Whether the pivot table field setting is updated successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
const valueId = fPivotTable?.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)[0]
if (fPivotTable && valueId) {
  await fPivotTable.setFieldSetting(valueId, {
    displayName: 'Revenue',
    format: '$#,##0',
    subtotalType: univerAPI.Enum.PivotSubtotalTypeEnum.sum,
  })
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IPivotTableFieldSettingOptions`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setLabelManualFilter`

Set the pivot table manual filter.

```typescript
setLabelManualFilter(tableFieldId: string, items: string[], isAll?: boolean): Promise<boolean>
```

**Parameters**

* `tableFieldId` — Required. The field id of the filter.
* `items` — Required. The items of the filter.
* `isAll` — Optional. Whether the filter is all.If true, the filter will be all items, the items will be ignored.

**Returns**

Whether the pivot table filter is set successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const rowIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
  if (rowIds.length > 0) {
    await fPivotTable.setLabelManualFilter(rowIds[0], ['item1', 'item2'])
  }
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setLabelSort`

Set the pivot table sort info.

```typescript
setLabelSort(tableFieldId: string, info: IPivotTableSortInfo): Promise<boolean>
```

**Parameters**

* `tableFieldId` — Required. The field id of the sort.
* `info` — Required. The sort info.

**Returns**

Whether the pivot table sort info is set successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const rowIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
  if (rowIds.length > 0) {
    await fPivotTable.setLabelSort(rowIds[0], {
      type: univerAPI.Enum.PivotDataFieldSortOperatorEnum.ascending,
    })
    // Advanced usage: persist an explicit label order. The same order is used by browser and Node.js calculations.
    await fPivotTable.setLabelSort(rowIds[0], {
      type: univerAPI.Enum.PivotDataFieldSortOperatorEnum.custom,
      customOrder: ['North', 'East', 'South', 'West'],
    })
  }
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IPivotTableSortInfo`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/interface.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setLayout`

Set the pivot table layout type through command. It keeps undo/redo, collaboration and render update paths consistent with panel operations.

```typescript
setLayout(layout: PivotLayoutTypeEnum): Promise<boolean>
```

**Parameters**

* `layout` — Required. The layout type to set.

**Returns**

Whether the pivot table layout is set successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fSheet = fWorkbook.getActiveSheet()
const subUnitId = fSheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
await fPivotTable?.setLayout(univerAPI.Enum.PivotLayoutTypeEnum.compact)
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`PivotLayoutTypeEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setOptions`

Set the display options of the pivot table through command. It keeps undo/redo, collaboration and render update paths consistent with panel operations.

```typescript
setOptions(options: IPivotTableOptions): Promise<boolean>
```

**Parameters**

* `options` — Required. The display options to set.

**Returns**

Whether the pivot table options are set successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), subUnitId, 0, 8)
await fPivotTable?.setOptions({
  repeatRowLabels: true,
  repeatColLabels: true,
  showRowGrandTotal: false,
  showColGrandTotal: true,
})
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IPivotTableOptions`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/layout-type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setShowDataAs`

Set the Show Values As configuration of a pivot table value field.

```typescript
setShowDataAs(fieldId: string, showDataAs: IPivotTableShowDataAsInfo): Promise<boolean>
```

**Parameters**

* `fieldId` — Required. The value field id.
* `showDataAs` — Required. The Show Values As configuration.

**Returns**

Whether the Show Values As configuration is set successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fPivotTable = fWorksheet.getPivotTableByCell(0, 8)
if (!fPivotTable) throw new Error('fPivotTable is not available')
const rowId = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)[0]
const valueId = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)[0]
if (rowId && valueId) {
  await fPivotTable.setShowDataAs(valueId, {
    type: univerAPI.Enum.PivotShowAsTypeEnum.differenceFrom,
    baseFieldId: rowId,
    baseItem: '',
    baseItemType: univerAPI.Enum.PivotShowAsBaseItemTypeEnum.previous,
  })
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IPivotTableShowDataAsInfo`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/interface.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setSourceRange`

Update the source range of the pivot table through command.

```typescript
setSourceRange(dataRangeInfo: IUnitRangeNameWithSubUnitId): Promise<boolean>
```

**Parameters**

* `dataRangeInfo` — Required. The new source data range info.

**Returns**

Whether the source range is updated successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const unitId = fWorkbook.getId()
const subUnitId = fWorksheet.getSheetId()
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
await fPivotTable?.setSourceRange({
  unitId,
  subUnitId,
  sheetName: fWorksheet.getSheetName(),
  range: {
    startRow: 0,
    endRow: 100,
    startColumn: 0,
    endColumn: 6,
  },
})
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IUnitRangeNameWithSubUnitId`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/const/type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setSubtotalType`

Set the pivot table subtotal type for value field, it only works for the value field.

```typescript
setSubtotalType(fieldId: string, subtotalType: PivotSubtotalTypeEnum): Promise<boolean>
```

**Parameters**

* `fieldId` — Required. The field id.
* `subtotalType` — Required. The subtotal type of the field.

**Returns**

Whether the pivot table subtotal type is set successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const valueId = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)[0]
  if (valueId) {
    await fPivotTable.setSubtotalType(valueId, univerAPI.Enum.PivotSubtotalTypeEnum.average)
  }
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`PivotSubtotalTypeEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.setValueFilter`

Set or replace the value filter owned by a row or column field. Each label field can own at most one rule. New rules are appended to the evaluation order, while replacing a rule keeps its current position. Use `count` or `percent` with `isBottom` to configure Top/Bottom filters.

```typescript
setValueFilter(fieldId: string, filterInfo?: Omit<IPivotTableValueFilter, 'type'>): Promise<boolean>
```

**Parameters**

* `fieldId` — Required. The row or column field id that owns the rule.
* `filterInfo` — Optional. The filter configuration. Pass `undefined` to remove the current rule. `valueFieldId` must reference an existing value field. Between operators use a two-number `expected` array; other operators use a number.

**Returns**

Whether the pivot table value filter is set successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const rowIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
  const valueIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Value)
  if (valueIds.length > 0 && rowIds.length > 0) {
    await fPivotTable.setValueFilter(rowIds[0], {
      operator: univerAPI.Enum.PivotFilterOperatorEnum.valueGreaterThan,
      expected: 10,
      valueFieldId: valueIds[0],
    })
  }
  // Remove the value filter while keeping other ordered rules unchanged.
  // await fPivotTable.clearValueFilter(rowIds[0]);
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`Omit`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IPivotTableValueFilter`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/interface.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.updateFieldPosition`

Update the pivot table field position.

```typescript
updateFieldPosition(fieldId: string, area: PivotTableFiledAreaEnum, index: number): Promise<boolean>
```

**Parameters**

* `fieldId` — Required. The moved field id.
* `area` — Required. The target area of the field.
* `index` — Required. The target index of the field, if the index is bigger than the field count in the target area, the field will be moved to the last, if the index is smaller than 0, the field will be moved to the first.

**Returns**

Whether the pivot field is moved successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  const rowIds = fPivotTable.getFieldIdsByArea(univerAPI.Enum.PivotTableFiledAreaEnum.Row)
  if (rowIds.length > 0) {
    // move to column
    await fPivotTable.updateFieldPosition(
      rowIds[0],
      univerAPI.Enum.PivotTableFiledAreaEnum.Column,
      0,
    )
  }
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`PivotTableFiledAreaEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.updateSourceRange`

Update the source range of the pivot table through command. This is an alias of setSourceRange.

```typescript
updateSourceRange(dataRangeInfo: IUnitRangeNameWithSubUnitId): Promise<boolean>
```

**Parameters**

* `dataRangeInfo` — Required. The new source data range info.

**Returns**

Whether the source range is updated successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const fPivotTable = fWorkbook.getPivotTableByCell(fWorkbook.getId(), fWorksheet.getSheetId(), 0, 8)
await fPivotTable?.updateSourceRange({
  unitId: fWorkbook.getId(),
  subUnitId: fWorksheet.getSheetId(),
  sheetName: fWorksheet.getSheetName(),
  range: { startRow: 0, endRow: 100, startColumn: 0, endColumn: 6 },
})
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`IUnitRangeNameWithSubUnitId`](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/const/type.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

### `FPivotTable.updateValuePosition`

If there are multiple value fields in the pivot table, you can update the position of the value field, which only can be position in row or column.

```typescript
updateValuePosition(position: PivotTableValuePositionEnum, index: number): Promise<boolean>
```

**Parameters**

* `position` — Required. The position of the value field.
* `index` — Required. The index of the value field.

**Returns**

Whether the pivot value field is moved successfully.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook.getId()
const fWorksheet = fWorkbook.getSheetByName('Sheet1')
if (!fWorksheet) throw new Error('fWorksheet is not available')
const subUnitId = fWorksheet.getSheetId()
// Here we assume that you already have a pivot table in cell A8 of the table.
// If not, please call fWorkbook.addPivotTable() according to the documentation.
const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)
if (fPivotTable) {
  // The prerequisite here is that the value dimension has more than one item
  await fPivotTable.updateValuePosition(univerAPI.Enum.PivotTableValuePositionEnum.Row, 0)
}
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64/lib/lib.es5.d.ts) · [`PivotTableValuePositionEnum`](https://unpkg.com/@univerjs-pro/engine-pivot/lib/types/types/enum.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot/lib/types/facade/f-pivot-table.d.ts)

## `@univerjs-pro/sheets-pivot-chart`

### `FPivotTable.newChart`

Creates a detached PivotChart Builder permanently linked to this PivotTable.

Any Pivot report edit made through the table or one of its linked charts updates the one
shared PivotModel. Chart visuals and Drawing placement remain independent per chart.

```typescript
newChart<T extends PivotChartTypeString>(type: T): FLinkedSheetPivotChartBuilderOf<T>
```

**Parameters**

* `type` — Required. The supported Chart type.

**Returns**

A prelinked, source-locked Builder.

**Examples**

```ts
import '@univerjs-pro/sheets-pivot-chart/facade'

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getSheetByName('Dashboard')
const fPivotTable = fWorkbook.getPivotTableById('pivot-table-1')
if (!fWorksheet || !fPivotTable) throw new Error('Pivot source is unavailable.')

const first = await fWorksheet.insertPivotChart(
  fPivotTable.newChart(univerAPI.Enum.ChartTypeString.Column).setPosition('A1').build(),
)
const second = await fWorksheet.insertPivotChart(
  fPivotTable.newChart(univerAPI.Enum.ChartTypeString.Line).setPosition('J1').build(),
)
console.log(first.getPivotTableReference(), second.getPivotTableReference())
```

**Types:** [`FLinkedSheetPivotChartBuilderOf`](https://unpkg.com/@univerjs-pro/sheets-pivot-chart/lib/types/facade/f-pivot-chart-builder.d.ts)

**Package:** [`@univerjs-pro/sheets-pivot-chart`](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot-chart.md) · [Type definitions](https://unpkg.com/@univerjs-pro/sheets-pivot-chart/lib/types/facade/f-pivot-table.d.ts)
