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="showDataTable()">Show Data Table</button>
<button onclick="showAirlineTotals()">Show Airline Totals</button>
<button onclick="showSalesTotals()">Show Sales Totals</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(),
mapping: {
"AIRLINE": {
"type": "string"
},
"STATE": {
"type": "string"
},
"Year": {
"type": "string"
},
"Month": {
"type": "month"
},
"Passengers": {
"type": "number"
},
"Sales (Fares Only)": {
"type": "number"
}
}
},
"slice": {
"rows": [{
"uniqueName": "AIRLINE"
},
{
"uniqueName": "STATE"
},
{
"uniqueName": "Year",
"filter": {
"members": [
"year.[2019]",
"year.[2020]"
]
}
},
{
"uniqueName": "[Measures]"
}
],
"columns": [{
"uniqueName": "Month"
}],
"measures": [{
"uniqueName": "Sales (Fares Only)",
"aggregation": "sum"
},
{
"uniqueName": "Passengers",
"aggregation": "sum"
}
],
"expands": {
"expandAll": true
}
},
"options": {
"grid": {
"type": "classic",
"showTotals": "off",
"showGrandTotals": "off"
}
}
},
width: "100%",
height: 600
});
pivot.on("reportcomplete", sortMonths);
function sortMonths() {
pivot.off("reportcomplete", sortMonths);
const sortOrder = ["JAN", "FEB", "MAR", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]
setSortOrder("Month", sortOrder);
}
function setSortOrder(uniqueName, sortOrder) {
pivot.sortingMethod(uniqueName, function(a, b) {
return sortOrder.indexOf(a) - sortOrder.indexOf(b);
});
}
function showDataTable() {
var slice = {
"rows": [{
"uniqueName": "AIRLINE"
},
{
...