APIs

WebPivotTable provides lots of APIs for developers to call them from hosted web page or web application. For example, developers can use these APIs to load source data from any kind of resources, or save reports to local files or server then reload them in future, etc.

How to call APIs?

WebPivotTable follow web component standard. We can put WebPivotTable on any web page just like it is a HTML tag. When web page loaded, there is a corresponding element created on DOM. Then we can call document.getElementsByTagName to get an javascript object of the element. Each API of WebPivotTable is a method of this javascript object.

Below is standard syntax to call APIs:

var wpt = document.getElementsByTagName('web-pivot-table')[0];

wpt.apiName(params1, params2, ..., paramsn);

Most of WebPivotTable APIs are asynchronous, it will return a Promise.

setLocale

wpt.setLocale(locale);
Param NameParam TypeOptionalDescription
localeStringnolocale code

setOptions

wpt.setOptions(options);
Param NameParam TypeOptionalDescription
optionsObjectnocustomize options

This setOptions API is a major way to customize WebPivotTable, see Options for more details.

getOptions

var options = wpt.getOptions();

showControlPanel

wpt.showControlPanel();

hideControlPanel

wpt.hideControlPanel();

toggleControlPanel

wpt.toggleControlPanel();

openDialog

wpt.openDialog({ type: "" , width: "", height: ""});
Param NameParam TypeOptionalDescription
typeStringno
widthStringyes
heightStringyes
payloadObjectyes

closeDialog

wpt.closeDialog();

reset

wpt.reset();

refresh

wpt.refresh();

loadingMessage

wpt.loadingMessage(message);
Param NameParam TypeOptionalDescription
messageStringno

clearMessage

wpt.clearMessage();

errorMessage

wpt.errorMessage(error);
Param NameParam TypeOptionalDescription
errorString or Objectno

setWptFromDataArray

wpt.setWptFromDataArray(attrArray, dataArray, dataUrl, url, type);
Param NameParam TypeOptionalDescription
attrArrayArraynoArray of attributes. example: ["department", "area", "cost", ...]
dataArrayArraynoArray of data rows, each row is also an array of values. example: [["dep1", "area1", 1000, ...], ..., ["dep6", "area2", 2000,...]]
urlStringyesUrl for track the source data, This is just for tracking, pass "" if not know or no need.
typeObjectyespre-saved wpt JSON object

Load source data from data array

Notes:

  • This is major API to load source data into WebPivotTable, it was used by setWptFromCsvUrl and setWptFromExcelUrl internally. Actually, developers can load any kinds of data from any other resources, like SQL databases, and format them as attrArray and dataArray, then load them into WebPivotTable.

getSourceFromDataArray

wpt.getSourceFromDataArray(attrArray, dataArray, dataUrl, url, type);
Param NameParam TypeOptionalDescription
attrArrayArraynoArray of attributes. example: ["department", "area", "cost", ...]
dataArrayArraynoArray of data rows, each row is also an array of values. example: [["dep1", "area1", 1000, ...], ..., ["dep6", "area2", 2000,...]]
urlStringyesUrl for track the source data, This is just for tracking, pass "" if not know or no need.
typeObjectyespre-saved wpt JSON object

setWptFromCsvUrl

wpt.setWptFromCsvUrl(url, delimiter);
Param NameParam TypeOptionalDescription
urlStringnoURL String of CSV file
delimiterStringyesseparator char for CSV file, default is ","

Set wpt from CSV file URL

getSourceFromCsvUrl

wpt.getSourceFromCsvUrl(url, delimiter);
Param NameParam TypeOptionalDescription
urlStringnoURL String of CSV file
delimiterStringyesseparator char for CSV file, default is ","

Load source data from CSV file URL

setWptFromExcelUrl

wpt.setWptFromExcelUrl(url, delimiter);
Param NameParam TypeOptionalDescription
urlStringnoURL String of Excel file
delimiterStringyesseparator char for Excel file, default is ","

Set wpt from Excel file URL

getSourceFromExcelUrl

wpt.getSourceFromExcelUrl(url, delimiter);
Param NameParam TypeOptionalDescription
urlStringnoURL String of Excel file
delimiterStringyesseparator char for Excel file, default is ","

Load source data from Excel file URL

setWptFromWebService

wpt.setWptFromWebService(url);
Param NameParam TypeOptionalDescription
urlStringnoURL String of Web Service

Set wpt from Web Service

getSourceFromWebService

wpt.getSourceFromWebService(url);
Param NameParam TypeOptionalDescription
urlStringnoURL String of Web Service

Load source data from Web Service URL

setWptFromGoogleSpreadSheet

wpt.setWptFromGoogleSpreadSheet(url);
Param NameParam TypeOptionalDescription
urlStringnoURL String of Google Spread Sheet

Set wpt from Google Spread Sheet

getSourceFromGoogleSpreadSheet

wpt.getSourceFromGoogleSpreadSheet(url);
Param NameParam TypeOptionalDescription
urlStringnoURL String of Google Spread Sheet

Load source data from Google Spread Sheet URL

setWptFromWptUrl

wpt.setWptFromWptUrl(url);
Param NameParam TypeOptionalDescription
urlStringnoURL String of wpt file

Set wpt from wpt file

setWptFromLocalFile

wpt.setWptFromLocalFile(file, type);
Param NameParam TypeOptionalDescription
fileObjectnolocal file
typeStringnofile type

Set wpt from local file

setWpt

wpt.setWpt(wpt);
Param NameParam TypeOptionalDescription
wptString or Objectnowpt string or object

Set wpt from wpt string or object

setWptFromOlapCube

wpt.setWptFromOlapCube(olapData);
Param NameParam TypeOptionalDescription
olapDataObjectnoObject of OLAP Cube Information

Load OLAP Cube

olapData: {
  xmlaUrl: "Xmla server url",
  dataSourceInfo: "Data source info",
  catalog: "Catalog name",
  cubeName: "Cube name"
}

getSourceFromOlapCube

wpt.getSourceFromOlapCube(olapData);
Param NameParam TypeOptionalDescription
olapDataObjectnoObject of OLAP Cube Information
olapData: {
  xmlaUrl: "Xmla server url",
  dataSourceInfo: "Data source info",
  catalog: "Catalog name",
  cubeName: "Cube name"
}

Load source data from Olap Cube

generateWptString

wpt.generateWptString(ignoreData);
Param NameParam TypeOptionalDescription
ignoreDataBooleannoif equal to true, ignore data and fields, only save options and controls

Generate WPT format string

generateWptJSON

wpt.generateWptJSON(ignoreData);
Param NameParam TypeOptionalDescription
ignoreDataBooleannoif equal to true, ignore data and fields, only save options and controls

Generate WPT format JSON object

getSourceObject

wpt.getSourceObject();

Get source object

setSourceObject

wpt.setSourceObject(source);
Param NameParam TypeOptionalDescription
sourceObjectno

Set source object