@univerjs-pro/engine-pivot
Version:
Pivot table calculation engine for Univer Pro.
86 lines (85 loc) • 3.64 kB
TypeScript
import type { IDataFieldInfo, IFieldsCollectionJSON } from '../types';
import type { DataFieldManager } from './data-field-manager';
import { DataField } from './data-field';
/**
* Represents the collection of fields in the pivot table. which one to one with a pivot table.
* @description The collection of fields in the pivot table. The fields collection uses shared the base data field id.For Grouped fields or calculated fields, it will save in custom field.
* @class FieldsCollection
* @param {DataFieldManager} host - The data field manager.
*/
export declare class FieldsCollection {
/**
* @property The base fields id which saved in host <the DataFieldManager>, this part of fields are the original fields in the pivot table.
*/
fieldIds: string[];
/**
* @property The display name of the fields in the pivot table. key is field id, value is the display name.
*/
displayNameRecord: Record<string, string>;
/**
* @property The custom fields in the pivot table. such as calculated fields or grouped fields.
*/
customFields: Record<string, DataField>;
range: any;
dataRecordCount: number;
readonly host: DataFieldManager;
constructor(host: DataFieldManager);
getFieldIds(): string[];
getFieldDisplayNames(): string[];
getFieldIdByDisplayName(name: string): string | undefined;
/**
* Get the dependency relationship between normal datafield and groupField under the current collection to reduce the number of loops
*/
getGroupFieldMap(): Map<string, string>;
/**
* Get all groupField and original datafield dependencies based on the passed ids
*/
getGroupFieldsInfoByIds(ids: string[]): [string, string][];
hasField(fieldId: string): boolean;
/**
* find the is there has a data field whose name is the same as the sourceName.
* @param {string} sourceName - the source name of the field.
* @returns {boolean} - true if has the field, otherwise false.
*/
hasSourceName(sourceName: string): boolean;
setRange(range: any): void;
/**
* - add a field to the collection. the field should be ensured in the host.
* @param fieldId
*/
addField(fieldId: string, displayName: string): void;
/**
* - delete a field from the collection.
* @param fieldId
*/
deleteField(fieldId: string): void;
/**
* get the display name of the field by the field id in this collection, in different collection, the display name may be different.
* @param {string} fieldId the data field id.
* @returns {string} the display name of the field.
*/
getDisplayName(fieldId: string): string;
setDisplayName(fieldId: string, fieldName: string, displayNameRecord?: Record<string, string>): void;
getUniqueDataFieldName(displayName: string, displayNameRecord?: Record<string, string>): string;
/**
* @description remove the field from the collection.
*/
updateAllDisplayName(): void;
/**
* @description Gets the field by the specified id.
* @param {string} id - The field id.
* @returns {DataField} - The field.
*/
getFieldById(id: string): DataField;
setDataRecordCount(count: number): void;
getDataRecordCount(): number;
getDataFieldBySourceName(sourceName: string): DataField | undefined;
/**
* @description Gets the field by the specified name.
* @returns {IDataFieldInfo[]} -returns the field infos.
*/
getFieldInfo(): IDataFieldInfo[];
toJSON(): IFieldsCollectionJSON;
fromJSON(jsonData: IFieldsCollectionJSON): void;
dispose(): void;
}