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 DOM "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](/doc/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
typeobjectno
widthobjectno
heightobjectno
payloadobjectno

`closeDialog`

wpt.closeDialog();

`setDataArray`
wpt.$eventBus.$emit("setDataArray", attrArray, dataArray, dataUrl, wptObject, successCB, errorCB);
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,...]]
dataUrlstringyesUrl for track the source data, This is just for tracking, pass "" if not know or no need.
wptObjectobjectyespre-saved wpt JSON object
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Load source data from data array

Notes:

  • If wptObject is not null, use it as pre-saved pivot selections

  • This is major API to load source data into WebPivotTable, it was used by setCsvUrl and setCsvRawData 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.

`setCsvUrl`
wpt.$eventBus.$emit("setCsvUrl", csvUrl, separator, wptObject, successCB, errorCB);
Param NameParam TypeOptionalDescription
csvUrlstringnoURL String of CSV file
separatorstringyesseparator char for CSV file, default is ","
wptObjectobjectyespre-saved wpt JSON object
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Load source data from CSV file URL

Notes:

  • If wptObject is not null, use it as pre-saved pivot selections

`setWptString`
wpt.$eventBus.$emit("setWptString", wptString, dataObject, successCB, errorCB);
Param NameParam TypeOptionalDescription
wptStringstringnopre-saved WPT format string
dataObjectobjectyesif exist, use this as data and fields of first source , format {data:[], fields:[]}
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Load WPT format String

`setWptObject`
wpt.$eventBus.$emit("setWptObject", wptObject, dataObject, successCB, errorCB);
Param NameParam TypeOptionalDescription
wptObjectobjectnopre-saved WPT format JSON object
dataObjectobjectyesif exist, use this as data and fields of first source , format {data:[], fields:[]}
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Load WPT format JSON Oject

`setWpt`
wpt.$eventBus.$emit("setWpt", wpt, dataObject, successCB, errorCB);
Param NameParam TypeOptionalDescription
wptstring\objectnopre-saved WPT format String or JSON object
dataObjectobjectyesif exist, use this as data and fields of first source , format {data:[], fields:[]}
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Load WPT format String or JSON Object with updated first source data

`generateWptString`
wpt.$eventBus.$emit("generateWptString", ignoreData, successCB);
Param NameParam TypeOptionalDescription
ignoreDataboolnoif equal to true, ignore data and fields, only save options and controls
successCBfunctionyessuccess callback, in this callback, generate wptString will be published as first parameter

Generate WPT format string

`generateWptJSON`
wpt.$eventBus.$emit("generateWptJSON", ignoreData, successCB);
Param NameParam TypeOptionalDescription
ignoreDataboolnoif equal to true, ignore data and fields, only save options and controls
successCBfunctionyessuccess callback, in this callback, generate wpt object will be published as first parameter

Generate WPT format JSON object

`setOlapCube`
wpt.$eventBus.$emit("setOlapCube", olapData, successCB, errorCB);
Param NameParam TypeOptionalDescription
olapDataObjectnoObject of OLAP Cube Information
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Load OLAP Cube

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

`setWebServiceDataUrl`
wpt.$eventBus.$emit("setWebServiceDataUrl", wsDataUrl, wptObject, successCB, errorCB);
Param NameParam TypeOptionalDescription
wsDataUrlstringnoURL String of Web Service Data URL
wptObjectobjectyespre-saved wpt JSON object
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Load source data from WebService URL and create a new WPT with a new Sheet

Notes:

  • If wptObject is not null, use it as pre-saved pivot selections

  • The Web Service should return a JSON object

         {
             attrArray: [],
             dataArray: []
         }
  • This is a very useful API to access data in SQL databases or any other data storages since Web Service access is cross domain and can be provided by any backend technologies.

`addWebServiceDataUrl`
wpt.$eventBus.$emit("addWebServiceDataUrl", wsDataUrl, successCB, errorCB);
Param NameParam TypeOptionalDescription
wsDataUrlstringnoURL String of Web Service Data URL
successCBfunctionyessuccess callback, in this callback, current wpt object will be published as first parameter
errorCBfunctionyeserror callback, in this callback, error object will be published as first parameter

Add a new source data from WebService URL

Notes:

  • The Web Service should return a JSON object
         {
             attrArray: [],
             dataArray: []
         }
  • This is a very useful API to access data in SQL databases or any other data storages since Web Service access is cross domain and can be provided by any backend technologies.