JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<button onclick="loadNewData(true)">Load Empty Dataset</button>
<button onclick="loadNewData(false)">Load Valid Dataset</button>
<div id="pivot-container"></div>
JavaScript
var currentReport = {
dataSource: {
filename: "https://cdn.flexmonster.com/data/data.json",
mapping: {
"Country": {
type: "string"
},
"Category": {
type: "string"
},
"Color": {
type: "string"
},
"Price": {
type: "number"
},
"Quantity": {
type: "number"
}
}
},
slice: {
rows: [{
uniqueName: "Country"
}, {
uniqueName: "Category"
}, {
uniqueName: "[Measures]"
}],
columns: [{
uniqueName: "Color"
}],
measures: [{
uniqueName: "Price"
}, {
uniqueName: "Quantity"
}],
},
options: {
configuratorActive: false,
showEmptyData: true
}
};
var pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
report: currentReport,
width: "100%",
height: 570,
reportcomplete: function() {
if (pivot.getReport().slice != null) {
currentReport = pivot.getReport();
} else {
currentReport.dataSource.data = [{}];
delete currentReport.dataSource.filename;
pivot.setReport(currentReport);
}
}
});
function loadNewData(isEmpty) {
let report = pivot.getReport();
if (report.slice == null) {
report = currentReport;
}
report.dataSource.filename = isEmpty ?
"https://www.flexmonster.com/fm_uploads/2020/04/empty.json" :
"https://cdn.flexmonster.com/data/data.json";
currentReport = report;
pivot.setReport(report);
}