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="setMapping()">Set mapping #1</button>
<button onclick="setMapping(true)">Set mapping #2</button>
<button onclick="getMapping()">Get mapping</button>
<div id="pivot-container"></div>
JavaScript
let mapping = {
"Color": {
"type": "string",
"caption": "Color"
},
"M": {
"type": "month",
"caption": "Month"
},
"W": {
"type": "weekday",
"caption": "Week Day"
},
"Country": {
"type": "level",
"hierarchy": "Geography",
"level": "Country"
},
"State": {
"type": "level",
"hierarchy": "Geography",
"level": "State",
"parent": "Country"
},
"City": {
"type": "level",
"hierarchy": "Geography",
"parent": "State"
},
"Price": {
"type": "number"
},
"Quantity": {
"type": "number"
}
}
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
data: getData(),
mapping: mapping
},
slice: {
columns: [{
uniqueName: "Color"
}],
rows: [{
uniqueName: "W"
}],
measures: [{
uniqueName: "Price"
}]
}
}
});
function getMapping() {
alert("The mapping object in your browser's console");
console.log(flexmonster.getReport().dataSource.mapping);
}
function setMapping(n) {
let report = flexmonster.getReport();
let mapping = {
"Color": {
"type": "string",
"caption": "Color"
},
"M": {
"type": "month",
"caption": "Month"
},
"W": {
"type": "weekday",
"caption": "Week Day"
},
"Country": {
"type": "level",
"hierarchy": "Geography",
"level": "Country"
},
"State": {
"type": "level",
"hierarchy": "Geography",
"level": "State",
"parent": "Country"
},
"City": {
"type": "level",
"hierarchy": "Geography",
"parent": "State"
},
"Price": {
"type": "number"
},
"Quantity": {
"type": "number"
}
}
if (n) {
mapping.Color.caption = "Custom Color Caption";
mapping.W.caption = "Custom Week Day Caption";
}
report.dataSource.mapping =...