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="pivotContainer"></div>
CSS
.dropdown {
position: relative;
margin: 0px !important;
padding: 0px !important;
z-index: 100;
}
.dropbtn {
font-size: 12px;
border: none;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
z-index: 200;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
JavaScript
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
data: getData()
},
slice: {
rows: [{
uniqueName: 'Product'
}],
measures: [{
uniqueName: 'Drop-down',
grandTotalCaption: "Drop-down"
}, {
uniqueName: 'Price'
}]
},
tableSizes: {
rows: [{
idx: 1,
height: 70
}, {
idx: 2,
height: 70
}, {
idx: 3,
height: 70
}]
},
}
});
pivot.customizeCell((cell, data) => {
if (data.measure && data.measure.uniqueName == 'Drop-down' && data.type == 'value') {
if (data.isTotal) cell.text = '';
else {
cell.text = `<div class="dropdown">
<div class="dropbtn">Dropdown ↓</div>
<div class="dropdown-content">
<div onclick='alert("Tab 1 clicked")'>Tab 1</div>
<div onclick='alert("Tab 2 clicked")'>Tab 2</div>
<div onclick='alert("Tab 3 clicked")'>Tab 3</div>
</div>
</div>`
}
}
});
function getData() {
return [{
"Product": "Cars",
"Price": 2400,
"Drop-down": ""
},
{
"Product": "Bikes",
"Price": 8903,
"Drop-down": ""
},
{
"Product": "Bikes",
"Price": 1711,
"Drop-down": ""
},
{
"Product": "Cars",
"Price": 8013,
"Drop-down": ""
},
{
"Product": "Helicopters",
"Price": 2511,
"Drop-down": ""
},
{
"Product": "Bikes",
"Price": 4692,
"Drop-down": ""
}
]
}