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>
JavaScript
let pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
filename: "data/data.csv"
},
options: {
drillThrough: false,
grid: {
type: "flat",
showTotals: "off",
showGrandTotals: "off"
}
},
slice: {
flatOrder: ["Color"]
}
},
beforegriddraw: function() {
const hierarchyIndex = findHierarchyIndex(conditionHierarchy);
if (hierarchyIndex >= 0) {
let rowIndexes = [...document.querySelectorAll(".fm-row")].map(row => row.getAttribute('data-r'));
rowIndexes = [...new Set(rowIndexes)].filter(rowNum => rowNum > 0);
rowsWithCondition = []
for (let i of rowIndexes) {
if (flexmonster.getCell(i, hierarchyIndex).label == conditionMember) {
rowsWithCondition.push(+i);
}
}
}
},
aftergriddraw: function() {
let rows = [];
for (let i of rowsWithCondition) {
document.querySelectorAll(`.fm-cell[data-r="${i}"]`).forEach(function(node) {
node.style.backgroundColor = "#AEC670";
node.style.color = '#344C11';
node.style.fontFamily = 'Times New Roman';
});
}
}
});
const conditionHierarchy = 'Color';
const conditionMember = 'green';
let rowsWithCondition = [];
function findHierarchyIndex(uniqueName) {
let colIdx = 0;
while (flexmonster.getCell(0, colIdx) != null) {
if (flexmonster.getCell(0, colIdx).hierarchy.uniqueName == uniqueName) {
return colIdx;
}
colIdx++;
}
return -1;
}
function getData() {
return [{
accountId: 23,
name: "My test acccount XYZ",
status: "Active",
statusId: "Active",
address: "321 Michigan Sq., #55"
}, {
accountId: 32,
name: "My test acccount ABC",
status: "Inactive",
statusId: "Inactive",
address: "123 Oxford Av., #23",
},
{
accountId: 33,
name: "My test...