JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
October 05, 2020
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<h3>
Use the Field List to modify the configuration
</h3>
<div id="pivotContainer"></div>
<div class="info">
<h3>
The report will appear below after the update. Changes are highlighted.<br>
Last update: <span id="timestamp"></span>
</h3>
<div id="monitor"></div>
</div>
CSS
#monitor {
white-space: pre;
padding: 10px;
overflow: auto;
height: 300px;
box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.302), 0 1px 3px 1px rgba(60, 64, 67, 0.149);
}
.info {
width: 70%;
margin-right: auto;
margin-left: auto;
}
.highlight {
background-color: #8BC34A;
}
JavaScript
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
height: 400,
report: {
dataSource: {
type: "api",
url: "https://olap.flexmonster.com:9500",
index: "fm-product-sales"
},
"slice": {
"rows": [{
"uniqueName": "Color"
}],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum"
}]
}
},
fieldslistopen: onPopupOpen,
fieldslistclose: onPopupClose
});
function onPopupOpen() {
flexmonster.on("reportchange", saveCurrentConfiguration);
}
function onPopupClose() {
flexmonster.off("reportchange");
}
function saveCurrentConfiguration() {
let report = flexmonster.getReport();
document.getElementById("monitor").innerHTML =
highlight(JSON.stringify(report, null, 4),
document.getElementById("monitor").innerText);
document.getElementById("timestamp").innerText = new Date().toLocaleTimeString();
}
function highlight(newElem, oldElem) {
let oldText = oldElem,
text = '';
newElem.split('').forEach(function(val, i) {
if (val != oldText.charAt(i)) text += `<span class='highlight'>${val}</span>`;
else text += val;
});
return text;
}