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="showSubtotals()">Show subtotals</button>
<button onclick="hideSubtotals()">Hide subtotals</button>
<button onclick="collapse()">Collapse data</button>
<button onclick="viewOnlyMeasures()">View only measures</button>
<div id="pivot-container"></div>
JavaScript
var pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
type: "json",
data: getData()
},
"slice": {
"columns": [{
"uniqueName": "Color"
},
{
"uniqueName": "Country"
},
{
"uniqueName": "Business Type"
},
{
"uniqueName": "Category"
}
],
"rows": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum"
},
{
"uniqueName": "Quantity",
"aggregation": "sum"
},
{
"uniqueName": "Size",
"aggregation": "count"
},
{
"uniqueName": "Discount",
"aggregation": "sum"
},
{
"uniqueName": "Destination",
"aggregation": "count"
}
],
"expands": {
"columns": [{
"tuple": [
"color.[green]"
]
}]
}
},
"options": {
grid: {
showTotals: "off"
}
}
},
width: "100%",
height: 500
});
function showSubtotals() {
pivot.setOptions({
grid: {
showTotals: "on"
}
})
pivot.refresh();
}
function hideSubtotals() {
pivot.setOptions({
grid: {
showTotals: "off"
}
})
pivot.refresh();
}
function collapse() {
pivot.collapseAllData();
}
function viewOnlyMeasures() {
let slice = pivot.getReport().slice;
slice.columns = [];
slice.rows = [{
"uniqueName": "[Measures]"
}];
pivot.runQuery(slice);
}
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",
...