JSFiddle - React, Tailwind, and code Playground
Customizing the grid
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>
CSS
.notexpandable {
cursor: initial;
}
JavaScript
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
customizeCell: customizeCellFunction,
report: {
dataSource: {
filename: "data/data.json",
},
slice: {
rows: [
{
uniqueName: "Category",
},
],
columns: [
{
uniqueName: "Color",
filter: {
members: ["color.[blue]"],
},
},
{
uniqueName: "Country",
},
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "Price",
aggregation: "sum",
},
],
expands: {
columns: [
{
tuple: ["color.[blue]"],
},
],
},
},
options: {
grid: {
showTotals: "off",
},
},
},
})
function customizeCellFunction(cell, data) {
if (
data.hierarchy &&
data.hierarchy.uniqueName == "Color"
) {
let parts = cell.text.split(data.escapedLabel)
if (parts.length == 2) {
cell.text = `<div class='notexpandable' onclick='preventExpand(event)'>${data.escapedLabel}</div>${parts[1]}`
}
}
}
function preventExpand(e) {
e.stopImmediatePropagation()
}