Skip to content

Commit afccc95

Browse files
"initialData" option add
1 parent c515322 commit afccc95

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.6.4",
4+
"version": "1.6.5",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
8080
[ , enableListingSelect: true ] // enable listing selection, true by default
8181
[ , showListingRowsNumber: true ] // show rows number in listing and tables if paginated
8282
[ , rowCount: 5 ] // number of rows to show. Use lp.setRowCount(N) to change rowCount. Manual lp.refresh() needed to apply.
83+
[ , initialData: { ... } ] // initial data from /MDX query (if present, in MDX2JSON format). Pivot won't request /MDX first time if initial data set. Check twice that dataSource.basicMDX is consistent with the data in this option.
8384
},
8485
lp = new LightPivotTable(setup);
8586

source/js/DataSource.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* @param {Object} config
77
* @param {Object} globalConfig
88
* @param {LightPivotTable} lpt
9+
* @param {number=1} [drillLevel]
910
* @constructor
1011
*/
11-
var DataSource = function (config, globalConfig, lpt) {
12+
var DataSource = function (config, globalConfig, lpt, drillLevel) {
1213

1314
this.SOURCE_URL = config.MDX2JSONSource ||
1415
location.host + ":" + location.port + "/" + (location.pathname.split("/") || [])[1];
@@ -18,9 +19,9 @@ var DataSource = function (config, globalConfig, lpt) {
1819
this.LPT = lpt;
1920
this.GLOBAL_CONFIG = globalConfig;
2021
this.SEND_COOKIES = config["sendCookies"] || false;
22+
this.DRILL_LEVEL = typeof drillLevel !== "number" ? 1 : drillLevel;
2123

2224
this.BASIC_MDX = config.basicMDX;
23-
2425
/**
2526
* Name of data source pivot.
2627
*
@@ -232,18 +233,27 @@ DataSource.prototype.getCurrentData = function (callback) {
232233

233234
if (_.LPT.CONFIG["logs"]) console.log("LPT MDX request:", mdx);
234235

236+
var setData = function (data) {
237+
_.LPT.pivotView.removeMessage();
238+
ready.data = data;
239+
ready.state++;
240+
handleDataReady();
241+
};
242+
243+
// fill initial data first time and exit
244+
if (_.DRILL_LEVEL === 0 && _.LPT.CONFIG["initialData"]) {
245+
setData(_.LPT.CONFIG["initialData"]);
246+
return;
247+
}
248+
235249
_._post(
236250
_.SOURCE_URL + "/" +
237251
(mdxType === "drillthrough" ? "MDXDrillthrough" : "MDX")
238252
+ (_.NAMESPACE ? "?Namespace=" + _.NAMESPACE : ""
239253
), {
240254
MDX: mdx
241-
}, function (data) {
242-
_.LPT.pivotView.removeMessage();
243-
ready.data = data;
244-
ready.state++;
245-
handleDataReady();
246-
});
255+
}, setData);
256+
247257
};
248258

249259
_.LPT.pivotView.displayLoading();

source/js/LightPivotTable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ LightPivotTable.prototype.pushDataSource = function (config) {
183183
var newDataSource;
184184

185185
this.DRILL_LEVEL++;
186-
this._dataSourcesStack.push(newDataSource = new DataSource(config || {}, this.CONFIG, this));
186+
this._dataSourcesStack.push(
187+
newDataSource = new DataSource(config || {}, this.CONFIG, this, this.DRILL_LEVEL)
188+
);
187189
this.dataSource = newDataSource;
188190

189191
return newDataSource;

0 commit comments

Comments
 (0)