JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
October 28, 2020
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="showY()">
Show for Y
</button>
<button onclick="showN()">
Show for N
</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: {
"Category": {
type: "string"
},
"Size": {
type: "string"
},
"Color": {
type: "string"
},
"Destination": {
type: "string"
},
"Business Type": {
type: "string"
},
"Country": {
type: "string"
},
"Price": {
type: "number"
},
"Quantity": {
type: "number"
},
"Discount": {
type: "number"
},
"Flag": {
type: "string",
filters: false
},
}
},
slice: {
"reportFilters": [{
"uniqueName": "Flag",
"filter": {
"members": [
"flag.[n]"
]
}
}, {
"uniqueName": "Destination"
}],
rows: [{
uniqueName: "Category"
}],
columns: [{
uniqueName: "Color"
}],
measures: [{
uniqueName: "Price"
}],
}
},
width: "100%",
height: 500
});
function showY() {
pivot.setFilter("Flag", {
"members": [
"flag.[y]"
]
})
}
function showN() {
pivot.setFilter("Flag", {
"members": [
"flag.[n]"
]
})
}
function getData() {
return [{
"Category": "Accessories",
"Size": "262 oz",
"Color": "red",
"Destination": "Australia",
"Business Type": "Specialty Bike Shop",
"Country": "Australia",
"Price": 174,
"Quantity": 225,
"Discount": 23,
"Flag": "Y"
}, {
"Category": "Accessories",
"Size": "214 oz",
"Color": "yellow",
"Destination": "Canada",
"Business Type": "Specialty Bike Shop",
"Country": "Canada",
"Price": 502,
"Quantity": 90,
"Discount": 17,
"Flag": "N"
...