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
new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 550,
toolbar: true,
report: {
options: {
grid: {
type: 'classic',
showGrandTotals: 'rows',
dragging: false,
},
configuratorActive: true,
configuratorButton: true,
fieldListPosition: 'right',
},
"dataSource": {
"type": "api",
"url": pivotEndpoint,
"mapping": {
"Country": {
"type": "string",
hierarchy: "Item",
},
"Category": {
"type": "string",
hierarchy: "Item",
parent: "Country"
},
"Color": {
"type": "string",
hierarchy: "Item",
parent: "Category"
}
}
},
"slice": {
"rows": [{
"uniqueName": "Item",
"levelName": "Country"
}],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum"
}],
"drills": {
"rows": [{
"tuple": [
"item.[australia]"
]
}]
}
},
}
});
function pivotEndpoint(request, successCallback, errorCallback) {
request = JSON.parse(request);
var result = null;
if (request.type == "fields") {
result = getSchema(request.index);
} else if (request.type == "members") {
result = getMembers(request.index, request.field, request.page);
} else if (request.type == "select") {
result = getReversedSelectResult(request.index, request.query, request.page);
}
successCallback(result);
}
function getSchema(index) {
return {
"fields": [{
"uniqueName": "Category",
"type": "string"
},
{
"uniqueName": "Size",
"type": "string"
},
{
"uniqueName": "Color",
"type": "string"
},
{
"uniqueName": "Destination",
...