JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
<div id="pivot-container"></div>
<div class="output" id="output">Output will appear here</div>
CSS
.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
const pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
height: 400,
report: {
dataSource: {
filename: "data/data.csv"
},
slice: {
rows: [{
uniqueName: "Category"
}, {
uniqueName: "Color"
}],
measures: [{
uniqueName: "Price",
aggregation: "sum"
}]
}
}
});
let prevReport;
flexmonster.on("reportcomplete", () => {
flexmonster.off("reportcomplete");
prevReport = flexmonster.getReport();
flexmonster.on("reportchange", () => {
const currReport = flexmonster.getReport();
const prevExpands = prevReport.slice.expands;
const currExpands = currReport.slice.expands;
const changed = !_.isEqual(prevExpands, currExpands);
if(changed){
//do whan you need
showOutput(prevExpands,currExpands);
prevReport = currReport;
}
});
});
function showOutput(before,after) {
let content = "expands changed from \n";
content += before?JSON.stringify(before):"nothing";
content+='\nto\n'
content += after?JSON.stringify(after):"nothing";
document.getElementById("output").innerText = content;
}