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>
JavaScript
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 430,
toolbar: true,
customizeCell: function(cell, data) {
if (data && data.isClassicTotalRow) {
if (data.rows && data.rows.length == 2 && data.rows[1].hierarchyUniqueName == "state") {
// it's a state subtotal, leave label
} else {
cell.text = ""; // hide label
}
}
},
report: {
dataSource: {
data: getData()
},
slice: {
rows: [{
uniqueName: "country"
}, {
uniqueName: "state"
}, {
uniqueName: "Color"
}],
columns: [],
measures: [{
uniqueName: "Price"
}],
expands: {
rows: [{
tuple: [
"country.[canada]"
]
}]
}
},
options: {
grid: {
type: "classic",
showTotals: true
}
}
}
});
function getData() {
return [{
"Color": "green",
"country": "Canada",
"state": "Ontario",
"Price": 174
}, {
"Color": "red",
"country": "Canada",
"state": "Quebec",
"Price": 1190
}, {
"Color": "green",
"country": "USA",
"state": "California",
"Price": 1222,
}, {
"Color": "red",
"country": "Canada",
"state": "Ontario",
"Price": 6829,
}, {
"Color": "green",
"country": "Canada",
"state": "Quebec",
"Price": 2995,
}, {
"Color": "yellow",
"country": "Canada",
"state": "Ontario",
"Price": 6650,
}, {
"Color": "blue",
"country": "Canada",
"state": "Ontario",
"Price": 865,
}, {
"Color": "purple",
"country": "Spain",
"state": "Andalusia",
"Price": 511,
}, {
"Color": "blue",
"country": "Canada",
"state": "Quebec",
"Price": 981,
}, {
"Color": "blue",
"country": "Canada",
"state": "Ontario",
"Price": 284,
}];
}