diff --git a/package.json b/package.json index d1bed84..33c4d61 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/readme.md b/readme.md index 76bb3ad..d154f95 100644 --- a/readme.md +++ b/readme.md @@ -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); diff --git a/source/js/DataSource.js b/source/js/DataSource.js index 52b61ed..3edb8af 100644 --- a/source/js/DataSource.js +++ b/source/js/DataSource.js @@ -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]; @@ -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. * @@ -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(); diff --git a/source/js/LightPivotTable.js b/source/js/LightPivotTable.js index 1bd3eef..47e106d 100644 --- a/source/js/LightPivotTable.js +++ b/source/js/LightPivotTable.js @@ -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;