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 class="note">
Double click on the cell â–Ľ
</div>
<div id="wrapper"></div>
<div id="pivot-container"></div>
CSS
.view {
position: absolute;
height: 300px;
width: 70%;
top: 75px;
z-index: 2;
left: 15%;
border-radius: 3px;
border: 1px solid #bebebe;
background-color: white;
}
.button {
float: right;
margin-right: 10px;
margin-top: 9px;
border-radius: 3px;
}
.info {
margin-left: 20px;
margin-top: 30px;
font-size: 12px;
width: 200px;
}
.note {
border: 2px solid #df3800;
background: #fff;
color: #df3800;
text-transform: uppercase;
cursor: pointer;
margin: 5px 0;
display: inline-block;
font-weight: normal;
padding: 10px 10px;
font-size: 14px;
}
JavaScript
new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 430,
toolbar: true,
report: {
dataSource: {
filename: "data/sales.csv"
},
options: {
drillThrough: false
},
slice: {
columns: [{
uniqueName: "Month"
}, {
uniqueName: "[Measures]"
}],
rows: [{
uniqueName: "Category",
filter: {
members: [
"category.[condiments].[bbq sauce]",
"category.[breakfast cereals].[corn flakes]",
"category.[confectionery]",
"category.[bakery].[chocolate biscuits]",
"category.[fruit preserves].[apple jam]",
"category.[bakery].[apple cake]",
"category.[soups].[tomato soup]"
]
}
}],
measures: [{
"uniqueName": "Revenue",
"aggregation": "sum",
"format": "2sfou03a"
}]
}
}
});
flexmonster.on('celldoubleclick', 'showDetails');
function showDetails(cell) {
console.log(cell);
var view = document.createElement("div");
view.classList.add("view");
view.id = "view";
document.getElementById("wrapper").appendChild(view);
var button = document.createElement("button");
button.classList.add("button");
button.id = "button";
button.innerHTML = "Close";
button.setAttribute("onclick", "removeElement('view')");
document.getElementById("view").appendChild(button);
var info = document.createElement("div");
info.classList.add("info");
info.innerHTML =
"Label: " + cell.label + "; " +
"Type: " + cell.type + "; " +
"Hierarchy: " + cell.hierarchy.uniqueName + "; " +
"More information can be found in your browser's console"
document.getElementById("view").appendChild(info);
};
function removeElement(elementId) {
var element = document.getElementById(elementId);
element.parentNode.removeChild(element);
}