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.
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.
wpt.setLocale(locale);
Param Name | Param Type | Optional | Description |
---|---|---|---|
locale | String | no | locale code |
wpt.setOptions(options);
Param Name | Param Type | Optional | Description |
---|---|---|---|
options | Object | no | customize options |
This
setOptions
API is a major way to customize WebPivotTable, see Options for more details.
var options = wpt.getOptions();
wpt.showControlPanel();
wpt.hideControlPanel();
wpt.toggleControlPanel();
wpt.openDialog({ type: "" , width: "", height: ""});
Param Name | Param Type | Optional | Description |
---|---|---|---|
type | String | no | |
width | String | yes | |
height | String | yes | |
payload | Object | yes |
wpt.closeDialog();
wpt.reset();
wpt.refresh();
wpt.loadingMessage(message);
Param Name | Param Type | Optional | Description |
---|---|---|---|
message | String | no |
wpt.clearMessage();
wpt.errorMessage(error);
Param Name | Param Type | Optional | Description |
---|---|---|---|
error | String or Object | no |
wpt.setWptFromDataArray(attrArray, dataArray, dataUrl, url, type);
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,...]] |
url | String | yes | Url for track the source data, This is just for tracking, pass "" if not know or no need. |
type | Object | yes | pre-saved wpt JSON object |
Load source data from data array
Notes:
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.wpt.getSourceFromDataArray(attrArray, dataArray, dataUrl, url, type);
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,...]] |
url | String | yes | Url for track the source data, This is just for tracking, pass "" if not know or no need. |
type | Object | yes | pre-saved wpt JSON object |
wpt.setWptFromCsvUrl(url, delimiter);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of CSV file |
delimiter | String | yes | separator char for CSV file, default is "," |
Set wpt from CSV file URL
wpt.getSourceFromCsvUrl(url, delimiter);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of CSV file |
delimiter | String | yes | separator char for CSV file, default is "," |
Load source data from CSV file URL
wpt.setWptFromExcelUrl(url, delimiter);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of Excel file |
delimiter | String | yes | separator char for Excel file, default is "," |
Set wpt from Excel file URL
wpt.getSourceFromExcelUrl(url, delimiter);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of Excel file |
delimiter | String | yes | separator char for Excel file, default is "," |
Load source data from Excel file URL
wpt.setWptFromWebService(url);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of Web Service |
Set wpt from Web Service
wpt.getSourceFromWebService(url);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of Web Service |
Load source data from Web Service URL
wpt.setWptFromGoogleSpreadSheet(url);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of Google Spread Sheet |
Set wpt from Google Spread Sheet
wpt.getSourceFromGoogleSpreadSheet(url);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of Google Spread Sheet |
Load source data from Google Spread Sheet URL
wpt.setWptFromWptUrl(url);
Param Name | Param Type | Optional | Description |
---|---|---|---|
url | String | no | URL String of wpt file |
Set wpt from wpt file
wpt.setWptFromLocalFile(file, type);
Param Name | Param Type | Optional | Description |
---|---|---|---|
file | Object | no | local file |
type | String | no | file type |
Set wpt from local file
wpt.setWpt(wpt);
Param Name | Param Type | Optional | Description |
---|---|---|---|
wpt | String or Object | no | wpt string or object |
Set wpt from wpt string or object
wpt.setWptFromOlapCube(olapData);
Param Name | Param Type | Optional | Description |
---|---|---|---|
olapData | Object | no | Object of OLAP Cube Information |
Load OLAP Cube
olapData: {
xmlaUrl: "Xmla server url",
dataSourceInfo: "Data source info",
catalog: "Catalog name",
cubeName: "Cube name"
}
wpt.getSourceFromOlapCube(olapData);
Param Name | Param Type | Optional | Description |
---|---|---|---|
olapData | Object | no | Object 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
wpt.generateWptString(ignoreData);
Param Name | Param Type | Optional | Description |
---|---|---|---|
ignoreData | Boolean | no | if equal to true, ignore data and fields, only save options and controls |
Generate WPT format string
wpt.generateWptJSON(ignoreData);
Param Name | Param Type | Optional | Description |
---|---|---|---|
ignoreData | Boolean | no | if equal to true, ignore data and fields, only save options and controls |
Generate WPT format JSON object
wpt.getSourceObject();
Get source object
wpt.setSourceObject(source);
Param Name | Param Type | Optional | Description |
---|---|---|---|
source | Object | no |
Set source object