The Pivot View Manager can be used to manage the saved views of a pivot table. It allows you to quickly access any saved view of the pivot table at a certain point in time. You can add, delete and modify the views in the pivot view manager.
Select a saved view from the 'Views' dropdown at the bottom of the pivot table panel then press the right checkmark next to it to change the view.
Views rely on the serialize() and deserialize() API to save and restore.
Serialize & Deserialize
Serialize current supports the following data:
Interface
interface GC.Spread.Pivot.ISerializeInfo
{
layoutType?: PivotTableLayoutType;
options?: object;
valuePosition?: GC.Pivot.IDataPosition;
pivotTablePosition?: [number, number];
fieldsInfo?: GC.Spread.Pivot.ISerializeFieldInfo[][];
}
interface GC.Spread.Pivot.ISerializeFieldInfo {
sourceName: string;
displayName: string;
index: number;
subtotal?: GC.Pivot.SubtotalType;
labelFilter?: GC.Spread.Pivot.IPivotTextFilterInfo | GC.Spread.Pivot.IPivotConditionFilterInfo;
valueFilter?: GC.Spread.Pivot.IPivotConditionFilterInfo;
sortInfo?: GC.Spread.Pivot.IPivotTableSortInfo;
}
API
///* function serialize (): GC.Spread.Pivot.ISerializeInfo
/**
* @description get serialized pivot table data
* @returns {GC.Spread.Pivot.ISerializeInfo} serialized pivot table data
*/
serialize (): GC.Spread.Pivot.ISerializeInfo
///* function deserialize (serializeInfo: GC.Spread.Pivot.ISerializeInfo)
/**
* @description restore serialized pivot table data to a existed pivot table
* @param {GC.Spread.Pivot.ISerializeInfo} serialized pivot table data
*/
deserialize (serializeInfo: GC.Spread.Pivot.ISerializeInfo)
Sample Code
var spread = new GC.Spread.Sheets.workbook(document.getElementById("ss"),{sheetCount:3});
var sourceSheet = spread.getSheet(0);
var sheet = spread.getSheet(1);
var sourceData = [["Date","Buyer","Type","Amount"],
["01-Jan","Mom","Fuel",74],
["15-Jan","Mom","Food",235],
["17-Jan","Dad","Sports",20],
["21-Jan","Kelly","Books",125]];
sourceSheet.setArray(0, 0, sourceData );
sourceSheet.tables.add('sourceData', 0, 0, 5, 4);
var layout = GC.Spread.Pivot.PivotTableLayoutType.compact;
var theme = GC.Spread.Pivot.PivotTableThemes.medium2;
var pivotTable = sheet.pivotTables.add("pivotTable_1", 'sourceData', 1, 1, layout, theme, options);
pivotTable.add("Buyer","Buyer",GC.Spread.Pivot.PivotTableFieldType.rowField);
pivotTable.add("Type","Type",GC.Spread.Pivot.PivotTableFieldType.columnField);
pivotTable.add("Amount","Sum of Amount",GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum);
var serialization = pivotTable.serialize();
pivotTable.remove('Type');
pivotTable.deserialize(serialization);
PivotTableViewManager
The PivotTableViewManager is used to add, delete, modify, and check Pivot Table Views.
The PivotTableViewManager and PivotTable have a one-to-one relationship, and it is initialized in the PivotTable constructor.
Interface
interface IPivotTableView{
name: string;
config: GC.Spread.Pivot.ISerializeInfo;
}
API
GC.Spread.Pivot.PivotTable
///* class GC.Spread.Pivot.PivotTable.PivotTableViewManager(applyCallback: Function, saveCallback: Function)
/**
* Represents a PivotTableViewManager.
* @class
*/
views
GC.Spread.Pivot.PivotTable.PivotTableViewManager
/**
* @description Add a view to pivot table views. A unique name is required when adding a view.
* @param {string} view Indicates the view to add.
* @example
* var viewsManager = pivotTable.views;
* viewsManager.add({
* name: 'config1',
* config: pivotTable.serialize()
* });
* viewsManager.get('config1');
*/
add(view: GC.Spread.Pivot.IPivotTableView): boolean;
/**
* @description Add a view to pivot table views. A unique name is required when adding a view.
* @param {string} name Indicates the name of view to save.
* @example
* var viewsManager = pivotTable.views;
* viewsManager.save('config1');
* viewsManager.get('config1');
*/
save(name: string): boolean;
/**
* @description get all views from pivot table views.
* @example
* var viewsManager = pivotTable.views;
* viewsManager.save('config1');
* console.log(viewsManager.all());
*/
all(): GC.Spread.Pivot.IPivotTableView[];
/**
* @description apply a view to current pivot table.
* @param {string} name Indicates the name of view to apply.
* @example
* var viewsManager = pivotTable.views;
* viewsManager.save('config1');
* viewsManager.apply('config1');
*/
apply(name: string): void;
/**
* @description get a view from pivot table views.
* @param {string} name Indicates the name of view to query.
* @example
* var viewsManager = pivotTable.views;
* viewsManager.save('config1');
* viewsManager.get('config1');
*/
get(name: string): GC.Spread.Pivot.IPivotTableView;
/**
* @description remove a view from pivot table views.
* @param {string} name Indicates the name of view to remove.
* @example
* var viewsManager = pivotTable.views;
* viewsManager.remove('config1');
* viewsManager.get('config1');
*/
remove(name: string): void;
If you set "viewList" to visible in the pivot panel, you can use it to control the views of a PivotTable. You can add, remove, and apply the views with the view list section at the bottom of the panel.
You can follow these steps:
Submit and view feedback for