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>
<select id="allFields" name="allFields" onChange="processInput()">
<option selected="" value="All">All</option>
<option value="Job">Job</option>
<option value="Category">Category</option>
</select>
<div id="pivot-container"></div>
CSS
select {
border: 2px solid #df3800;
border-radius: 4px;
background: #fff;
color: black;
text-transform: uppercase;
cursor: pointer;
margin: 5px 0;
display: inline-block;
-webkit-transition: all .3s;
transition: all .3s;
font-weight: normal;
padding: 10px 10px;
font-size: 14px;
}
JavaScript
let pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
type: "json",
data: getData(),
mapping: {
"Job_Code": {
"type": "string"
},
"Job_Desc": {
"type": "string"
},
"Unit_Weight": {
"type": "number"
},
"Dimension_Type": {
"type": "string"
},
"Category_Code": {
"type": "string"
},
"Category_Desc": {
"type": "string"
}
}
}
}
});
function processInput() {
const fieldsDropdown = document.getElementById("allFields");
const filterCriteria = fieldsDropdown.options[fieldsDropdown.selectedIndex].value;
if (filterCriteria === "Job") {
pivot.connectTo({
type: "json",
data: getData(),
mapping: {
"Job_Code": {
"type": "string"
},
"Job_Desc": {
"type": "string"
},
"Unit_Weight": {
"type": "number",
"visible": false
},
"Dimension_Type": {
"type": "string",
"visible": false
},
"Category_Code": {
"type": "string",
"visible": false
},
"Category_Desc": {
"type": "string",
"visible": false
}
}
});
} else if (filterCriteria === "Category") {
pivot.connectTo({
type: "json",
data: getData(),
mapping: {
"Job_Code": {
"type": "string",
"visible": false
},
"Job_Desc": {
"type": "string",
"visible": false
},
"Unit_Weight": {
"type": "number",
"visible": false
},
"Dimension_Type": {
"type": "string",
"visible": false
},
"Category_Code": {
"type": "string"
},
...