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 APIs are implemented based on event bus mechanism. An event bus is a mechanism that allows different components to communicate with each other without knowing about each other. A component can send an event to the event bus without knowing who will pick it up or how many others will pick it up. Components can also listen to events on an event bus, without knowing who sent the events. That way, components can communicate without depending on each other.
There is an "$eventBus" property of initialed WebPivotTable object. This property is an event bus. We can use it to emit events to WebPivotTable and trigger some internal logic of WebPivotTable. This event emit mechanism is the key how APIs works.
Below is standard syntax to call APIs:
var wpt = document.getElementsByTagName('web-pivot-table')[0];
wpt.$eventBus.$emit(apiName, params1, params2, ..., paramsn);
First, we need get WebPivotTable object, then call $emit method of this object's $eventBus props, passing with API name together with a list of params.
Since event bus is asynchronous, we should pass callbacks as params if we want to add some logic when API call succeed
with response or failed with error.
`setLocale`
wpt.$eventBus.$emit("setLocale", locale);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
locale |
string |
no | locale code |
`setOptions`
wpt.$eventBus.$emit("setOptions", options);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
options |
object |
no | customize options |
`setView`
wpt.$eventBus.$emit("setView", view);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
view |
string |
no | "SOURCE/SHEET/REPORT" |
`setDataArray` Available in the current release.
wpt.$eventBus.$emit("setDataArray", attrArray, dataArray, dataUrl, wptObject, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
attrArray |
array |
no | Array of attributes. example: ["department", "area", "cost", ...] |
dataArray |
array |
no | Array of data rows, each row is also an array of values. example: [["dep1", "area1", 1000, ...], ..., ["dep6", "area2", 2000,...]] |
dataUrl |
string |
yes | Url for track the source data, This is just for tracking, pass "" if not know or no need. |
wptObject |
object |
yes | pre-saved wpt JSON object |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error callback, in this callback, error object will be published as first parameter |
Load source data from data array
Notes:
If
wptObjectis not null, use it as pre-saved pivot selectionsThis is major API to load source data into WebPivotTable, it was used by
setCsvUrlandsetCsvRawDatainternally. 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` Available in the current release.
wpt.$eventBus.$emit("setCsvUrl", csvUrl, separator, wptObject, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
csvUrl |
string |
no | URL String of CSV file |
separator |
string |
yes | separator char for CSV file, default is "," |
wptObject |
object |
yes | pre-saved wpt JSON object |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error callback, in this callback, error object will be published as first parameter |
Load source data from CSV file URL
Notes:
- If
wptObjectis not null, use it as pre-saved pivot selections
`setWptString` Available in the current release.
wpt.$eventBus.$emit("setWptString", wptString, dataObject, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
wptString |
string |
no | pre-saved WPT format string |
dataObject |
object |
yes | if exist, use this as data and fields of first source , format {data:[], fields:[]} |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error callback, in this callback, error object will be published as first parameter |
Load WPT format String
`setWptObject` Available in the current release.
wpt.$eventBus.$emit("setWptObject", wptObject, dataObject, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
wptObject |
object |
no | pre-saved WPT format JSON object |
dataObject |
object |
yes | if exist, use this as data and fields of first source , format {data:[], fields:[]} |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error callback, in this callback, error object will be published as first parameter |
Load WPT format JSON Oject
`setWpt` Available in the current release.
wpt.$eventBus.$emit("setWpt", wpt, dataObject, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
wpt |
string\object |
no | pre-saved WPT format String or JSON object |
dataObject |
object |
yes | if exist, use this as data and fields of first source , format {data:[], fields:[]} |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error 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` Available in the current release.
wpt.$eventBus.$emit("generateWptString", ignoreData, successCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
ignoreData |
bool |
no | if equal to true, ignore data and fields, only save options and controls |
successCB |
function |
yes | success callback, in this callback, generate wptString will be published as first parameter |
Generate WPT format string
`generateWptJSON` Available in the current release.
wpt.$eventBus.$emit("generateWptJSON", ignoreData, successCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
ignoreData |
bool |
no | if equal to true, ignore data and fields, only save options and controls |
successCB |
function |
yes | success callback, in this callback, generate wpt object will be published as first parameter |
Generate WPT format JSON object
`setOlapCube` Available in the current release.
wpt.$eventBus.$emit("setOlapCube", olapData, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
olapData |
Object |
no | Object of OLAP Cube Information |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error 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` Available in the current release.
wpt.$eventBus.$emit("setWebServiceDataUrl", wsDataUrl, wptObject, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
wsDataUrl |
string |
no | URL String of Web Service Data URL |
wptObject |
object |
yes | pre-saved wpt JSON object |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error 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
wptObjectis not null, use it as pre-saved pivot selectionsThe 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` Available in the current release.
wpt.$eventBus.$emit("addWebServiceDataUrl", wsDataUrl, successCB, errorCB);
| Param Name | Param Type | Optional | Description |
|---|---|---|---|
wsDataUrl |
string |
no | URL String of Web Service Data URL |
successCB |
function |
yes | success callback, in this callback, current wpt object will be published as first parameter |
errorCB |
function |
yes | error 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.
