@univerjs-pro/engine-pivot v0.5.0-beta.1Docs


Class: PivotTable

PivotTable - represents the wrapper class pivot table.

Description

The pivot table is a wrapper class which references the data fields collection and pivot table model.

Implements

IPivotTable

Constructors

new PivotTable()

new PivotTable(dataFieldsCollection, model?): PivotTable

Parameters

ParameterType
dataFieldsCollectionFieldsCollection
model?PivotModel

Returns

PivotTable

Defined in

pivot/pivot-table.ts:28

Properties

PropertyTypeDefined in
_bufferModelPivotModelpivot/pivot-table.ts:25
dataFieldsCollectionFieldsCollectionpivot/pivot-table.ts:22

Methods

_generateModel()

_generateModel(): void

Returns

void

Defined in

pivot/pivot-table.ts:66


addField()

addField(
   field, 
   area, 
   index?): void

Parameters

ParameterType
fieldPivotTableValueField | PivotTableLabelField
areaPivotTableFiledAreaEnum
index?number

Returns

void

Example

const pt= new PivotTable(fieldsCollection);
var areaField = pt.addFieldWithSourceName('区域', PivotTableFiledAreaEnum.Column);
pt.addFieldWithSourceName('省份', PivotTableFiledAreaEnum.Filter);

Defined in

pivot/pivot-table.ts:395


addFieldWithSourceId()

addFieldWithSourceId(
   dataFieldId, 
   area, 
   index?): undefined | PivotTableValueField | PivotTableLabelField
  • add a field to the pivot table by the source name , if the field is a measure field, it will be use auto name.

Parameters

ParameterTypeDescription
dataFieldIdstringdata field name
areaPivotTableFiledAreaEnumthe area of the added field
index?numberthe position of the field in the area, if not set, the field will be added to the end of the area.

Returns

undefined | PivotTableValueField | PivotTableLabelField

the added field

Defined in

pivot/pivot-table.ts:271


createLabelFieldByDataFieldId()

createLabelFieldByDataFieldId(dataFieldId, tableName?): undefined | PivotTableLabelField

Parameters

ParameterType
dataFieldIdstring
tableName?string

Returns

undefined | PivotTableLabelField

Defined in

pivot/pivot-table.ts:70


createValueFieldByDataFieldId()

createValueFieldByDataFieldId(dataFieldId): undefined | PivotTableValueField

Parameters

ParameterType
dataFieldIdstring

Returns

undefined | PivotTableValueField

Defined in

pivot/pivot-table.ts:82


dispose()

dispose(): void

Returns

void

Defined in

pivot/pivot-table.ts:512


endCollectChangeset()

endCollectChangeset(): IPivotTableChangeSet[]

Returns

IPivotTableChangeSet[]

Defined in

pivot/pivot-table.ts:53


fromJSON()

fromJSON(data): void

Parameters

ParameterType
dataIPivotTableSnapshot

Returns

void

Defined in

pivot/pivot-table.ts:508


getDataFieldByDataFieldId()

getDataFieldByDataFieldId(dataFieldId): undefined | DataField
  • get the data field by the data field id

Parameters

ParameterTypeDescription
dataFieldIdstringthe data field id

Returns

undefined | DataField

the data field or undefined

Defined in

pivot/pivot-table.ts:241


getDataFieldByTableId()

getDataFieldByTableId(tableField): undefined | DataField
  • get the data field by the table field id

Parameters

ParameterTypeDescription
tableFieldstringthe table field id

Returns

undefined | DataField

the data field or undefined

Defined in

pivot/pivot-table.ts:187


getDataFieldItemInfo()

getDataFieldItemInfo(dataField): {
  items: string[];
  itemTypes: PivotDataFieldDataTypeEnum[];
}

Parameters

ParameterType
dataFieldDataField

Returns

{
  items: string[];
  itemTypes: PivotDataFieldDataTypeEnum[];
}
NameTypeDefined in
itemsstring[]pivot/pivot-table.ts:245
itemTypesPivotDataFieldDataTypeEnum[]pivot/pivot-table.ts:245

Defined in

pivot/pivot-table.ts:245


getFieldCountByArea()

getFieldCountByArea(area): number
  • get how many fields in the area

Parameters

ParameterTypeDescription
areaPivotTableFiledAreaEnumthe area of the field enum

Returns

number

the field count

Defined in

pivot/pivot-table.ts:157


getFieldFormat()

getFieldFormat(fieldId): undefined | string
  • get a format for pivot table field, which will be applied in the pivot table view. the label field will use the format to format the date value.

Parameters

ParameterTypeDescription
fieldIdstringthe field id

Returns

undefined | string

the field format code

Description

when a show data as type is selected, we should set the format for the field.

Defined in

pivot/pivot-table.ts:372


getFieldPositionInfoById()

getFieldPositionInfoById(fieldId): {
  area: undefined | PivotTableFiledAreaEnum;
  index: number;
}

Parameters

ParameterTypeDescription
fieldIdstringthe field id

Returns

{
  area: undefined | PivotTableFiledAreaEnum;
  index: number;
}
  • The position information of the field or undefined.
NameTypeDefined in
areaundefined | PivotTableFiledAreaEnumpivot/pivot-table.ts:431
indexnumberpivot/pivot-table.ts:431

Description

Get the field position information by the field id.

Defined in

pivot/pivot-table.ts:431


getFilterFieldIdByIndex()

getFilterFieldIdByIndex(index): undefined | string

get the filter information by the filter index

Parameters

ParameterTypeDescription
indexnumberThe index of the filter field.

Returns

undefined | string

the table field id

Defined in

pivot/pivot-table.ts:352


getFilterInfo()

getFilterInfo(fieldId): undefined | IPivotTableFilterInfo

Parameters

ParameterType
fieldIdstring

Returns

undefined | IPivotTableFilterInfo

Defined in

pivot/pivot-table.ts:343


getIndexesByPathStr()

getIndexesByPathStr(tuple): number[]

Find the tupleItem in the cache that matches the position order according to the passed array, and after obtaining the row number array marked on it, summarize and sort to get all the relevant source data rows

The key point here is that dimensionIdList and dimensionTableIdList are one-to-one index corresponding

Parameters

ParameterType
tuplestring[][]

Returns

number[]

-Sorted row numbers

Defined in

pivot/pivot-table.ts:454


getNeedQuery()

getNeedQuery(viewVersion): boolean
  • get the pivot view need query or not

Parameters

ParameterType
viewVersionnumber

Returns

boolean

  • need query or not

Defined in

pivot/pivot-table.ts:422


getOptions()

getOptions(): IPivotTableOptions

Returns

IPivotTableOptions

Defined in

pivot/pivot-table.ts:403


getSortInfo()

getSortInfo(fieldId): undefined | IPivotTableSortInfo
  • get the sort information of the dimension field.

Parameters

ParameterTypeDescription
fieldIdstringThe id of the field.

Returns

undefined | IPivotTableSortInfo

-The sort information of the field.

Defined in

pivot/pivot-table.ts:339


getTableFieldById()

getTableFieldById(tableFieldId): undefined | PivotTableValueField | PivotTableLabelField
  • get the table field by the table field id

Parameters

ParameterTypeDescription
tableFieldIdstringthe table field id

Returns

undefined | PivotTableValueField | PivotTableLabelField

the table field or undefined

Defined in

pivot/pivot-table.ts:215


getTableFieldsByDataFieldId()

getTableFieldsByDataFieldId(dataFieldId): (PivotTableValueField | PivotTableLabelField)[]
  • get all the table fields by use the data field id

Parameters

ParameterType
dataFieldIdstring

Returns

(PivotTableValueField | PivotTableLabelField)[]

the table field ids

Defined in

pivot/pivot-table.ts:200


getUniqueFieldId()

getUniqueFieldId(): string

Returns

string

Defined in

pivot/pivot-table.ts:252


getUniqueValueFieldName()

getUniqueValueFieldName(autoName): string
  • get a unique field name in the pivot table

Parameters

ParameterTypeDescription
autoNamestringthe given field name

Returns

string

the unique field name

Defined in

pivot/pivot-table.ts:170


getValueFields()

getValueFields(): string[]

Returns

string[]

Defined in

pivot/pivot-table.ts:161


getValueIndex()

getValueIndex(): number

get the order index of ΣValue in row or col

Returns

number

-1 means not exist, otherwise the index of the ΣValue

Defined in

pivot/pivot-table.ts:115


getValuePosition()

getValuePosition(): PivotTableValuePositionEnum
  • get the value position

Returns

PivotTableValuePositionEnum

the value position, only row or column

Defined in

pivot/pivot-table.ts:123


isColMultiMeasure()

isColMultiMeasure(): boolean

Returns

boolean

Defined in

pivot/pivot-table.ts:103


isEmpty()

isEmpty(): boolean
  • get the pivot table is empty or not

Returns

boolean

empty or not

Defined in

pivot/pivot-table.ts:232


isExistField()

isExistField(tableFieldId): boolean
  • check the field is exist in the pivot table or not

Parameters

ParameterTypeDescription
tableFieldIdstringthe check field id

Returns

boolean

exist or not

Defined in

pivot/pivot-table.ts:224


isRowMultiMeasure()

isRowMultiMeasure(): boolean

Returns

boolean

Defined in

pivot/pivot-table.ts:107


iterateField()

iterateField(callback): void
  • iterate all pivot table fields

Parameters

ParameterTypeDescription
callback(field) => voidthe callback function

Returns

void

Defined in

pivot/pivot-table.ts:131


iterateFieldByArea()

iterateFieldByArea(area, callback): void
  • iterate the field by the area

Parameters

ParameterTypeDescription
areaPivotTableFiledAreaEnumthe area of the field enum
callback(field) => voidthe callback function

Returns

void

Defined in

pivot/pivot-table.ts:148


iterateFieldDim()

iterateFieldDim(callback): void
  • iterate the dimension field, it means all the label fields

Parameters

ParameterTypeDescription
callback(field) => voidthe callback function

Returns

void

Defined in

pivot/pivot-table.ts:139


query()

query(config?): PivotView

Parameters

ParameterType
config?IPivotTableQueryData

Returns

PivotView

Defined in

pivot/pivot-table.ts:486


removeField()

removeField(fieldId): void

Parameters

ParameterType
fieldIdstring

Returns

void

Defined in

pivot/pivot-table.ts:399


renameField()

renameField(fieldId, displayName): void
  • Rename the field.

Parameters

ParameterTypeDescription
fieldIdstringThe id of the field.
displayNamestringThe display name of the field.

Returns

void

Defined in

pivot/pivot-table.ts:312


setCollapse()

setCollapse(
   fieldId, 
   collapse, 
   item?): void

Parameters

ParameterTypeDescription
fieldIdstringThe id of the field.
collapsebooleanThe collapse status of the field.
item?stringThe item of the field.

Returns

void

Description

Set the collapse status of the field. Those properties are used to save the collapse status of the field in the pivot table.

Defined in

pivot/pivot-table.ts:413


setDirty()

setDirty(dirty): void

Parameters

ParameterType
dirtyboolean

Returns

void

Defined in

pivot/pivot-table.ts:482


setFieldFormat()

setFieldFormat(fieldId, format): void
  • set the format for pivot table field, which will be applied in the pivot table view. the label field will use the format to format the date value.

Parameters

ParameterType
fieldIdstring
formatundefined | string

Returns

void

Description

when a show data as type is selected, we should set the format for the field. a label field which contains the date value should set the format.

Defined in

pivot/pivot-table.ts:382


setFilterInfo()

setFilterInfo(fieldId, filterInfo): void
  • Set the filter information of the dimension field. only the dimension field can set the filter information.

Parameters

ParameterType
fieldIdstring
filterInfoIPivotTableFilterInfo

Returns

void

Defined in

pivot/pivot-table.ts:321


setOptions()

setOptions(options): void

Parameters

ParameterType
optionsIPivotTableOptions

Returns

void

Defined in

pivot/pivot-table.ts:284


setSortInfo()

setSortInfo(fieldId, sortInfo): void
  • Set the sort information of the dimension field. only the dimension field can set the sort information.

Parameters

ParameterTypeDescription
fieldIdstringThe id of the field.
sortInfoundefined | IPivotTableSortInfoThe sort information of the field.

Returns

void

Defined in

pivot/pivot-table.ts:330


setSubtotalType()

setSubtotalType(fieldId, subtotalType): void
  • Set the subtotal type of the field. only the value field can set the subtotal type. only effective for the value field.

Parameters

ParameterTypeDescription
fieldIdstringThe id of the field.
subtotalTypePivotSubtotalTypeEnumThe subtotal type of the field.

Returns

void

Defined in

pivot/pivot-table.ts:303


startCollectChangeset()

startCollectChangeset(): void

Returns

void

Defined in

pivot/pivot-table.ts:48


toJSON()

toJSON(): IPivotTableSnapshot

Returns

IPivotTableSnapshot

Defined in

pivot/pivot-table.ts:504


updateDataFieldsCollection()

updateDataFieldsCollection(dataFieldsCollection): void

Parameters

ParameterType
dataFieldsCollectionFieldsCollection

Returns

void

Defined in

pivot/pivot-table.ts:37


updateFieldPosition()

updateFieldPosition(
   fieldId, 
   area, 
   index): void
  • set the position of the field in the pivot table. which used in pivot panel drag field.

Parameters

ParameterTypeDescription
fieldIdstringThe id of the pivot table field.
areaPivotTableFiledAreaEnumwhich area the field will be placed.
indexnumberthe index of the field in the area.

Returns

void

Defined in

pivot/pivot-table.ts:362


updateFieldSourceInfo()

updateFieldSourceInfo(
   fieldId, 
   sourceName, 
   dataFieldId): void

the func is only use for when refresh

Parameters

ParameterTypeDescription
fieldIdstringthe table field id
sourceNamestringthe source name of the field
dataFieldIdstringthe data field id

Returns

void

Defined in

pivot/pivot-table.ts:294


updateValuePosition()

updateValuePosition(valuePosition, valueIndex): void

Parameters

ParameterType
valuePositionPivotTableValuePositionEnum
valueIndexnumber

Returns

void

Defined in

pivot/pivot-table.ts:99