Skip to content

Commit

Permalink
"initialData" option add
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Jan 28, 2016
1 parent c515322 commit afccc95
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "LightPivotTable",
"author": "ZitRo",
"version": "1.6.4",
"version": "1.6.5",
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
"main": "test/testServer.js",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
[ , enableListingSelect: true ] // enable listing selection, true by default
[ , showListingRowsNumber: true ] // show rows number in listing and tables if paginated
[ , rowCount: 5 ] // number of rows to show. Use lp.setRowCount(N) to change rowCount. Manual lp.refresh() needed to apply.
[ , 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.
},
lp = new LightPivotTable(setup);

Expand Down
26 changes: 18 additions & 8 deletions source/js/DataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* @param {Object} config
* @param {Object} globalConfig
* @param {LightPivotTable} lpt
* @param {number=1} [drillLevel]
* @constructor
*/
var DataSource = function (config, globalConfig, lpt) {
var DataSource = function (config, globalConfig, lpt, drillLevel) {

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

this.BASIC_MDX = config.basicMDX;

/**
* Name of data source pivot.
*
Expand Down Expand Up @@ -232,18 +233,27 @@ DataSource.prototype.getCurrentData = function (callback) {

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

var setData = function (data) {
_.LPT.pivotView.removeMessage();
ready.data = data;
ready.state++;
handleDataReady();
};

// fill initial data first time and exit
if (_.DRILL_LEVEL === 0 && _.LPT.CONFIG["initialData"]) {
setData(_.LPT.CONFIG["initialData"]);
return;
}

_._post(
_.SOURCE_URL + "/" +
(mdxType === "drillthrough" ? "MDXDrillthrough" : "MDX")
+ (_.NAMESPACE ? "?Namespace=" + _.NAMESPACE : ""
), {
MDX: mdx
}, function (data) {
_.LPT.pivotView.removeMessage();
ready.data = data;
ready.state++;
handleDataReady();
});
}, setData);

};

_.LPT.pivotView.displayLoading();
Expand Down
4 changes: 3 additions & 1 deletion source/js/LightPivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ LightPivotTable.prototype.pushDataSource = function (config) {
var newDataSource;

this.DRILL_LEVEL++;
this._dataSourcesStack.push(newDataSource = new DataSource(config || {}, this.CONFIG, this));
this._dataSourcesStack.push(
newDataSource = new DataSource(config || {}, this.CONFIG, this, this.DRILL_LEVEL)
);
this.dataSource = newDataSource;

return newDataSource;
Expand Down

0 comments on commit afccc95

Please sign in to comment.