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="readOnly()">Make read only</button>
<button onclick="interactive()">Make interactive</button>
<div id="pivot-container"></div>
CSS
.fm-grid-view .fm-cell,
.fm-data-sheet {
border: 0px !important;
}
JavaScript
var pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
type: "json",
data: getData()
},
"slice": {
"rows": [{
"uniqueName": "Category"
}],
"columns": [{
"uniqueName": "Color"
},
{
"uniqueName": "[Measures]"
}
],
"measures": [{
"uniqueName": "Quantity",
"aggregation": "sum"
}]
},
options: {
configuratorActive: false,
grid: {
showHeaders: false
}
}
},
width: "100%",
height: 450
});
function readOnly() {
pivot.setOptions({
grid: {
showFilter: false,
dragging: false,
},
chart: {
showFilter: false,
},
configuratorButton: false,
sorting: false,
drillThrough: false,
});
hideContextMenu();
toggleToolbar(true);
pivot.refresh();
}
function interactive() {
pivot.setOptions({
grid: {
showFilter: true,
dragging: true,
},
chart: {
showFilter: true,
},
configuratorButton: true,
sorting: true,
drillThrough: true,
});
showContextMenu();
toggleToolbar(false);
pivot.refresh();
}
function hideContextMenu() {
pivot.customizeContextMenu(() => {
return [];
});
}
function showContextMenu() {
pivot.customizeContextMenu(null);
}
function toggleToolbar(hide) {
pivot.toolbar.toolbarWrapper.style.display = hide ? "none" : "block";
}
function getData() {
return [{
"Category": "Accessories",
"Size": "262 oz",
"Color": "red",
"Destination": "Australia",
"Business Type": "Specialty Bike Shop",
"Country": "Australia",
"Price": 174,
"Quantity": 225,
"Discount": 23
}, {
"Category": "Accessories",
"Size": "214 oz",
"Color": "yellow",
"Destination": "Canada",
"Business Type": "Specialty Bike Shop",
"Country": "Canada",
"Price": 502,
...