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>
<div id="custom-filter-popup-wrap">
<div id="custom-filter-popup-title"></div>
<select id="custom-filter-popup-select" class=""></select>
<div id="custom-filter-popup-buttons-wrap">
<button onclick="closeFilterPopup()">Cancel</button>
<button onclick="applyFilter()">Apply</button>
</div>
</div>
CSS
html,
body {
height: 100%;
margin: 0;
}
fm-pivot>div {
height: 100%;
}
#custom-filter-popup-wrap {
display: none;
flex-flow: column;
background-color: rgb(255, 255, 255);
box-shadow: 0 0 20px rgb(0 0 0 / 10%);
position: absolute;
padding: 10px;
width: 50%;
height: min-content;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
top: 0;
bottom: 0;
margin-top: auto;
margin-bottom: auto;
z-index: 200;
}
#custom-filter-popup-title {
padding: 10px;
font-size: 24px;
color: #111;
font-family: Arial, sans-serif;
}
#custom-filter-popup-select {
margin: 10px;
padding: 7px 40px 7px 12px;
border: 1px solid #E8EAED;
border-radius: 5px;
background: white;
box-shadow: 0 1px 3px -2px #9098A9;
cursor: pointer;
font-family: inherit;
font-size: 16px;
}
#custom-filter-popup-buttons-wrap {
margin: 10px 5px 10px 5px;
display: flex;
flex-direction: row;
}
#custom-filter-popup-wrap button {
display: block;
flex-grow: 1;
margin-left: 5px;
margin-right: 5px;
}
JavaScript
let pivot = new Flexmonster({
container: "#pivot-container",
toolbar: true,
componentFolder: "https://cdn.flexmonster.com/",
report: {
dataSource: {
filename: "https://cdn.flexmonster.com/data/data.json"
},
slice: {
rows: [{
uniqueName: "Category"
}],
columns: [{
uniqueName: "Color"
},
{
uniqueName: "[Measures]"
}
],
measures: [{
uniqueName: "Price",
aggregation: "sum"
}]
}
},
width: "100%",
height: "100%"
});
let selectionFlagObj = {
'Category': {
flag: "single",
},
'Size': {
flag: "multi",
},
'Color': {
flag: "multi",
},
'Destination': {
flag: "single",
},
'Business Type': {
flag: "single",
},
'Country': {
flag: "multi",
},
'Price': {
flag: "both",
},
'Quantity': {
flag: "both",
},
'Discount': {
flag: "both",
},
}
//Flexmonster-native elements
let pivotRef = document.getElementById("pivot-container");
let modalOverlayRef;
//Custom filter pop-up elements
let fpRef = document.getElementById("custom-filter-popup-wrap");
let fpTitleRef = document.getElementById("custom-filter-popup-title");
let fpSelectRef = document.getElementById("custom-filter-popup-select");
//uniqueName of the hierarchy to filter
let filterPopupHierarchyName;
flexmonster.on('filteropen', function(params) {
modalOverlayRef = document.querySelector('div[class="fm-ui-element fm-ui fm-ui-modal-overlay"]');
switch (selectionFlagObj[params.hierarchy.dimensionUniqueName].flag) {
case "single":
document.querySelector("div.fm-filter-view").style.opacity = "0";
openPivotPopup(params.hierarchy.dimensionUniqueName);
break;
case "multi":
document.querySelector("div.fm-filter-view").style.opacity = "1";
break;
case "both": {
alert("Display another custom pop-up window");
document.querySelector("div.fm-filter-view").style.opacity = "0";
...