JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<h3 class="text">
Click on a value cell to see the cell's details.
</h3>
<div id="pivot-container"></div>
<div class="output" id="output">Output will appear here</div>
CSS
.output {
width: 80%;
height: 300px;
margin-left: auto;
margin-right: auto;
padding: 20px;
background: rgba(242, 242, 242, 1);
font-family: Menlo, Monaco, "Courier New", Courier, monospace;
white-space: pre;
font-size: 16px;
font-weight: 400;
overflow-y: scroll;
margin-top: 20px;
}
.text {
padding: 10px;
}
JavaScript
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
data: getData(),
mapping: {
Country: {
type: "string", hierarchy: "Country"
},
Color: {
type: "string", hierarchy: "Country", parent: "Country"
}
}
},
"slice": {
"rows": [{
"uniqueName": "Country"
},
{
"uniqueName": "Color"
}
],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum"
}],
"expands": {
"rows": [{
"tuple": [
"country.[canada]"
]
}]
}
}
}
});
pivot.customizeContextMenu((items, data) => {
items = [];
items.push({
label: 'Get cell',
handler: ()=> {
console.log(data);
}
});
return items;
});
function getData() {
return [{
"Color": "green",
"M": "September",
"W": "Wed",
"Country": "Canada",
"State": "Ontario",
"City": "Toronto",
"Price": 174,
"Quantity": 22
}, {
"Color": "red",
"M": "March",
"W": "Mon",
"Time": "1000",
"Country": "USA",
"State": "California",
"City": "Los Angeles",
"Price": 1664,
"Quantity": 19
}, {
"Color": "red",
"M": "January",
"W": "Mon",
"Country": "Canada",
"State": "Quebec",
"City": "Montreal",
"Price": 1190,
"Quantity": 292
}, {
"Color": "green",
"D": "04/08/2014",
"M": "August",
"W": "Fri",
"Time": "1000",
"Country": "USA",
"State": "California",
"City": "Los Angeles",
"Price": 1222,
"Quantity": 730
}, {
"Color": "white",
"M": "March",
"W": "Wed",
"Country": "USA",
"State": "California",
...