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>
<div id="pivot-container"></div>
CSS
.notexpandable {
cursor: initial;
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
padding-left: inherit !important;
padding-top: inherit !important;
}
JavaScript
var pivot = new Flexmonster({
container: "#pivot-container",
toolbar: true,
componentFolder: "https://cdn.flexmonster.com/",
customizeCell: customizeCellFunction,
report: {
dataSource: {
type: "json",
data: getData()
},
slice: {
rows: [{
uniqueName: "Destination",
showTotals: false
},
{
uniqueName: "Country",
showTotals: true
}
],
columns: [{
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "Price",
aggregation: "sum"
}],
expands: {
rows: [{
tuple: [
"destination.[united states]"
]
}]
}
},
options: {
grid: {
type: "classic"
}
},
},
width: "100%",
height: 600
});
function customizeCellFunction(cell, data) {
if (data.hierarchy &&
data.member &&
data.hierarchy.uniqueName == "Destination" &&
data.member.uniqueName == "destination.[united states]" &&
data.isTotal == false) {
var parts = cell.text.split(data.escapedLabel);
if (parts.length == 2) {
cell.text = "<div class='notexpandable' onclick='preventExpand(event)'>" + data.escapedLabel + "</div>" + parts[1];
}
}
}
function preventExpand(e) {
e.stopImmediatePropagation();
}
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,
"Quantity": 90,
"Discount": 17
}, {
"Category": "Components",
"Size": "235 oz",
"Color": "green",
"Destination": "Australia",
"Business Type": "Warehouse",
...