@univerjs-pro/engine-pivot v0.5.4


Class: PivotTable

Defined in: pivot/pivot-table.ts:21

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

Defined in: pivot/pivot-table.ts:28

Parameters

ParameterType
dataFieldsCollectionFieldsCollection
model?PivotModel

Returns

PivotTable

Properties

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

Methods

_generateModel()

_generateModel(): void

Defined in: pivot/pivot-table.ts:66

Returns

void


addField()

addField(
   field, 
   area, 
   index?): void

Defined in: pivot/pivot-table.ts:395

Parameters

ParameterType
field| PivotTableValueField | PivotTableLabelField
areaPivotTableFiledAreaEnum
index?number

Returns

void

Example

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

addFieldWithSourceId()

addFieldWithSourceId(
   dataFieldId, 
   area, 
   index?): 
  | undefined
  | PivotTableValueField
  | PivotTableLabelField

Defined in: pivot/pivot-table.ts:271

  • 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


createLabelFieldByDataFieldId()

createLabelFieldByDataFieldId(dataFieldId, tableName?): undefined | PivotTableLabelField

Defined in: pivot/pivot-table.ts:70

Parameters

ParameterType
dataFieldIdstring
tableName?string

Returns

undefined | PivotTableLabelField


createValueFieldByDataFieldId()

createValueFieldByDataFieldId(dataFieldId): undefined | PivotTableValueField

Defined in: pivot/pivot-table.ts:82

Parameters

ParameterType
dataFieldIdstring

Returns

undefined | PivotTableValueField


dispose()

dispose(): void

Defined in: pivot/pivot-table.ts:512

Returns

void


endCollectChangeset()

endCollectChangeset(): IPivotTableChangeSet[]

Defined in: pivot/pivot-table.ts:53

Returns

IPivotTableChangeSet[]


fromJSON()

fromJSON(data): void

Defined in: pivot/pivot-table.ts:508

Parameters

ParameterType
dataIPivotTableSnapshot

Returns

void


getDataFieldByDataFieldId()

getDataFieldByDataFieldId(dataFieldId): undefined | DataField

Defined in: pivot/pivot-table.ts:241

  • get the data field by the data field id

Parameters

ParameterTypeDescription
dataFieldIdstringthe data field id

Returns

undefined | DataField

the data field or undefined


getDataFieldByTableId()

getDataFieldByTableId(tableField): undefined | DataField

Defined in: pivot/pivot-table.ts:187

  • get the data field by the table field id

Parameters

ParameterTypeDescription
tableFieldstringthe table field id

Returns

undefined | DataField

the data field or undefined


getDataFieldItemInfo()

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

Defined in: pivot/pivot-table.ts:245

Parameters

ParameterType
dataFieldDataField

Returns

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

getFieldCountByArea()

getFieldCountByArea(area): number

Defined in: pivot/pivot-table.ts:157

  • get how many fields in the area

Parameters

ParameterTypeDescription
areaPivotTableFiledAreaEnumthe area of the field enum

Returns

number

the field count


getFieldFormat()

getFieldFormat(fieldId): undefined | string

Defined in: pivot/pivot-table.ts:372

  • 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.


getFieldPositionInfoById()

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

Defined in: pivot/pivot-table.ts:431

Parameters

ParameterTypeDescription
fieldIdstringthe field id

Returns

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

Description

Get the field position information by the field id.


getFilterFieldIdByIndex()

getFilterFieldIdByIndex(index): undefined | string

Defined in: pivot/pivot-table.ts:352

get the filter information by the filter index

Parameters

ParameterTypeDescription
indexnumberThe index of the filter field.

Returns

undefined | string

the table field id


getFilterInfo()

getFilterInfo(fieldId): 
  | undefined
  | IPivotTableFilterInfo

Defined in: pivot/pivot-table.ts:343

Parameters

ParameterType
fieldIdstring

Returns

| undefined | IPivotTableFilterInfo


getIndexesByPathStr()

getIndexesByPathStr(tuple): number[]

Defined in: pivot/pivot-table.ts:454

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


getNeedQuery()

getNeedQuery(viewVersion): boolean

Defined in: pivot/pivot-table.ts:422

  • get the pivot view need query or not

Parameters

ParameterType
viewVersionnumber

Returns

boolean

  • need query or not

getOptions()

getOptions(): IPivotTableOptions

Defined in: pivot/pivot-table.ts:403

Returns

IPivotTableOptions


getSortInfo()

getSortInfo(fieldId): 
  | undefined
  | IPivotTableSortInfo

Defined in: pivot/pivot-table.ts:339

  • get the sort information of the dimension field.

Parameters

ParameterTypeDescription
fieldIdstringThe id of the field.

Returns

| undefined | IPivotTableSortInfo

-The sort information of the field.


getTableFieldById()

getTableFieldById(tableFieldId): 
  | undefined
  | PivotTableValueField
  | PivotTableLabelField

Defined in: pivot/pivot-table.ts:215

  • get the table field by the table field id

Parameters

ParameterTypeDescription
tableFieldIdstringthe table field id

Returns

| undefined | PivotTableValueField | PivotTableLabelField

the table field or undefined


getTableFieldsByDataFieldId()

getTableFieldsByDataFieldId(dataFieldId): (
  | PivotTableValueField
  | PivotTableLabelField)[]

Defined in: pivot/pivot-table.ts:200

  • get all the table fields by use the data field id

Parameters

ParameterType
dataFieldIdstring

Returns

( | PivotTableValueField | PivotTableLabelField)[]

the table field ids


getUniqueFieldId()

getUniqueFieldId(): string

Defined in: pivot/pivot-table.ts:252

Returns

string


getUniqueValueFieldName()

getUniqueValueFieldName(autoName): string

Defined in: pivot/pivot-table.ts:170

  • get a unique field name in the pivot table

Parameters

ParameterTypeDescription
autoNamestringthe given field name

Returns

string

the unique field name


getValueFields()

getValueFields(): string[]

Defined in: pivot/pivot-table.ts:161

Returns

string[]


getValueIndex()

getValueIndex(): number

Defined in: pivot/pivot-table.ts:115

get the order index of ΣValue in row or col

Returns

number

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


getValuePosition()

getValuePosition(): PivotTableValuePositionEnum

Defined in: pivot/pivot-table.ts:123

  • get the value position

Returns

PivotTableValuePositionEnum

the value position, only row or column


isColMultiMeasure()

isColMultiMeasure(): boolean

Defined in: pivot/pivot-table.ts:103

Returns

boolean


isEmpty()

isEmpty(): boolean

Defined in: pivot/pivot-table.ts:232

  • get the pivot table is empty or not

Returns

boolean

empty or not


isExistField()

isExistField(tableFieldId): boolean

Defined in: pivot/pivot-table.ts:224

  • check the field is exist in the pivot table or not

Parameters

ParameterTypeDescription
tableFieldIdstringthe check field id

Returns

boolean

exist or not


isRowMultiMeasure()

isRowMultiMeasure(): boolean

Defined in: pivot/pivot-table.ts:107

Returns

boolean


iterateField()

iterateField(callback): void

Defined in: pivot/pivot-table.ts:131

  • iterate all pivot table fields

Parameters

ParameterTypeDescription
callback(field) => voidthe callback function

Returns

void


iterateFieldByArea()

iterateFieldByArea(area, callback): void

Defined in: pivot/pivot-table.ts:148

  • iterate the field by the area

Parameters

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

Returns

void


iterateFieldDim()

iterateFieldDim(callback): void

Defined in: pivot/pivot-table.ts:139

  • iterate the dimension field, it means all the label fields

Parameters

ParameterTypeDescription
callback(field) => voidthe callback function

Returns

void


query()

query(config?): PivotView

Defined in: pivot/pivot-table.ts:486

Parameters

ParameterType
config?IPivotTableQueryData

Returns

PivotView


removeField()

removeField(fieldId): void

Defined in: pivot/pivot-table.ts:399

Parameters

ParameterType
fieldIdstring

Returns

void


renameField()

renameField(fieldId, displayName): void

Defined in: pivot/pivot-table.ts:312

  • Rename the field.

Parameters

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

Returns

void


setCollapse()

setCollapse(
   fieldId, 
   collapse, 
   item?): void

Defined in: pivot/pivot-table.ts:413

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.


setDirty()

setDirty(dirty): void

Defined in: pivot/pivot-table.ts:482

Parameters

ParameterType
dirtyboolean

Returns

void


setFieldFormat()

setFieldFormat(fieldId, format): void

Defined in: pivot/pivot-table.ts:382

  • 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.


setFilterInfo()

setFilterInfo(fieldId, filterInfo): void

Defined in: pivot/pivot-table.ts:321

  • Set the filter information of the dimension field. only the dimension field can set the filter information.

Parameters

ParameterType
fieldIdstring
filterInfoIPivotTableFilterInfo

Returns

void


setOptions()

setOptions(options): void

Defined in: pivot/pivot-table.ts:284

Parameters

ParameterType
optionsIPivotTableOptions

Returns

void


setSortInfo()

setSortInfo(fieldId, sortInfo): void

Defined in: pivot/pivot-table.ts:330

  • Set the sort information of the dimension field. only the dimension field can set the sort information.

Parameters

ParameterTypeDescription
fieldIdstringThe id of the field.
sortInfo| undefined | IPivotTableSortInfoThe sort information of the field.

Returns

void


setSubtotalType()

setSubtotalType(fieldId, subtotalType): void

Defined in: pivot/pivot-table.ts:303

  • 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


startCollectChangeset()

startCollectChangeset(): void

Defined in: pivot/pivot-table.ts:48

Returns

void


toJSON()

toJSON(): IPivotTableSnapshot

Defined in: pivot/pivot-table.ts:504

Returns

IPivotTableSnapshot


updateDataFieldsCollection()

updateDataFieldsCollection(dataFieldsCollection): void

Defined in: pivot/pivot-table.ts:37

Parameters

ParameterType
dataFieldsCollectionFieldsCollection

Returns

void


updateFieldPosition()

updateFieldPosition(
   fieldId, 
   area, 
   index): void

Defined in: pivot/pivot-table.ts:362

  • 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


updateFieldSourceInfo()

updateFieldSourceInfo(
   fieldId, 
   sourceName, 
   dataFieldId): void

Defined in: pivot/pivot-table.ts:294

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


updateValuePosition()

updateValuePosition(valuePosition, valueIndex): void

Defined in: pivot/pivot-table.ts:99

Parameters

ParameterType
valuePositionPivotTableValuePositionEnum
valueIndexnumber

Returns

void