Flexmonster updateData pivotEndpoint
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div>
<button onclick="refreshCustomData()">Refresh Custom DataSource</button>
</div>
<div id="pivotContainer"></div>
<div class="output" id="output">Output will appear here</div>
CSS
#pivotContainer .fm-drillthrough-view {
display: none !important;
}
.output {
width: 80%;
height: 300px;
margin-left: auto;
margin-right: auto;
padding: 20px;
background: rgba(242, 242, 242, 1);
font-family: Menlo, Monaco, "Courier New", Courier, monospace;
white-space: pre;
font-size: 16px;
font-weight: 400;
overflow-y: scroll;
margin-top: 20px;
}
JavaScript
let endpointUrl = "https://olap.flexmonster.com:9500/";
let index = "fm-product-sales";
let cache = {};
function pivotEndpoint(requestStringified, done) {
let request = JSON.parse(requestStringified);
let drillThrough = request.type == "select" && request.query.aggs === undefined;
if (drillThrough)
done({
"fields": [],
"hits": []
});
$.ajax({
type: "POST",
url: endpointUrl + request.type,
data: requestStringified,
success: response => {
if (!drillThrough) {
done(response);
} else {
showOutput(JSON.stringify(response, null, 4));
alert("Custom pop-up based on the received information");
}
},
dataType: "json",
contentType: "application/json"
});
}
let pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
"dataSource": {
"type": "api",
"url": pivotEndpoint,
"index": index,
concurrentRequests: true,
},
"slice": {
"rows": [{
"uniqueName": "Country"
}],
"columns": [{
"uniqueName": "[Measures]",
"uniqueName": "Size"
}],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum"
}]
}
}
});
flexmonster.on("drillthroughopen", () => {
document.querySelector("#pivotContainer .fm-drillthrough-view .fm-ui-btn-close").click();
});
function showOutput(content) {
document.getElementById("output").innerText = content;
}
function refreshCustomData() {
console.log("pivot.updateData");
pivot.updateData({
"type": "api",
"url": pivotEndpoint,
"index": index,
concurrentRequests: true,
},
{
ignoreScroll: false
});
}