JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container"></div>
<div id="popupOverlay" class='hideCustomPopup'></div>
<div id="custom-options-popup" class='hideCustomPopup'>
<div id="custom-options-popup-title">Cube Builder [IPN] Layout Options</div>
<h4> Grand Totals </h4>
<select id="custom-options-grand-totals-select">
<option selected value='on'>Show grand totals</option>
<option value='rows'>Show for rows</option>
<option value='column'>Show for coulmns</option>
<option value='off'>Do not show grand totals</option>
</select>
<h4> Subtotals </h4>
<select id="custom-options-subtotals-select">
<option selected value='on'>Show subtotals</option>
<option value='rows'>Show for rows</option>
<option value='column'>Show for coulmns</option>
<option value='off'>Do not show subtotals</option>
</select>
<h4> Layout </h4>
<select id="custom-options-layout-select">
<option value='flat'>Flat form</option>
<option value='classic'>Classic form</option>
<option value='compact' selected>Compact form</option>
</select>
<div id="custom-options-popup-buttons-wrap">
<button onclick="closeOptionsPopup()">Close</button>
<button onclick="submitOptions()" class='submit-btn'>Submit</button>
</div>
</div>
CSS
/* div.fm-filter-view.hideDefaultFilter {
z-index: -100 !important;
} */
.hideCustomPopup {
display: none !important;
}
#popupOverlay{
z-index: 199;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.7);
}
#custom-options-popup {
font-family: Arial, sans-serif;
flex-flow: column;
background-color: rgb(255, 255, 255);
box-shadow: 0 0 20px rgb(0 0 0 / 10%);
position: absolute;
padding: 40px;
width: 40%;
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-options-popup-title {
font-size: 24px;
font-family: Arial, sans-serif;
color: #af2935;
margin-bottom: 40px;
}
#custom-options-popup h4{
font-size: 16px;
margin: 20px 0 0 0;
}
#custom-options-popup select {
/* margin: 0; */
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-options-popup-buttons-wrap {
margin-top: 40px;
display: flex;
flex-direction: row;
gap: 5px;
}
#custom-options-popup-buttons-wrap button {
display: block;
flex-grow: 1;
border: none;
padding: 10px 15px;
color: #555;
background-color: white;
font-size: 18px;
}
#custom-options-popup-buttons-wrap button:hover{
cursor: pointer;
background-color: #f0f0f0;
}
#custom-options-popup-buttons-wrap .submit-btn{
color: white;
background-color: #555;
}
#custom-options-popup-buttons-wrap .submit-btn:hover{
background-color: #444;
}
JavaScript
let pivot = new Flexmonster({
container: "#pivot-container",
toolbar: true,
componentFolder: "https://cdn.flexmonster.com/",
beforetoolbarcreated: customizeToolbar,
report: {
dataSource: {
filename: "https://cdn.flexmonster.com/data/data.json"
},
slice: {
rows: [{
uniqueName: "Category"
}],
columns: [{
uniqueName: "Business Type"
},
{
uniqueName: "[Measures]"
}
],
measures: [{
uniqueName: "Price",
aggregation: "sum"
}]
}
}
});
function customizeToolbar(toolbar) {
let tabs = toolbar.getTabs();
toolbar.getTabs = function() {
let optionsTab = tabs.find(tab => tab.id == "fm-tab-options");
if (!optionsTab) return tabs;
optionsTab.handler = () => {
showOptionsPopup();
}
return tabs;
}
}
function showOptionsPopup() {
const popup = document.querySelector('#custom-options-popup');
const popoupOverlay = document.querySelector('#popupOverlay');
popup.classList.remove('hideCustomPopup');
popoupOverlay.classList.remove('hideCustomPopup');
popoupOverlay.onclick = closeOptionsPopup;
}
function closeOptionsPopup() {
const popup = document.querySelector('#custom-options-popup');
const popupOverlay = document.querySelector('#popupOverlay');
popup.classList.add('hideCustomPopup');
popupOverlay.classList.add('hideCustomPopup');
}
function submitOptions() {
const grandTotalsSelect = document.getElementById('custom-options-grand-totals-select');
const subtotalsSelect = document.getElementById('custom-options-subtotals-select');
const layoutSelect = document.getElementById('custom-options-layout-select');
// Get the selected values
const grandTotalsValue = grandTotalsSelect.value;
const subtotalsValue = subtotalsSelect.value;
const layoutValue = layoutSelect.value;
let options = pivot.getOptions();
options.grid.type = layoutValue;
options.grid.showTotals = subtotalsValue;
...