JSFiddle - React, Tailwind, and code Playground
Data source
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container"></div>
CSS
#fm-pivot-view .fm-grid-view div.fm-cell.highlighted-static {
background-color: #FFB8B8 !important;
}
JavaScript
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
customizeCell: customizeCellFunction,
toolbar: true,
report: {
dataSource: {
data: getData(),
},
slice: {
rows: [
{
uniqueName: "product",
},
],
columns: [
{
uniqueName: "order",
},
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "originalQty",
aggregation: "sum",
},
{
uniqueName: "qty",
aggregation: "sum",
},
],
},
conditions: [
{
measure: "qty",
formula: "sum('qty') != sum('originalQty')",
format: {
backgroundColor: "#ffee8c",
},
},
],
options: {
grid: {
showTotals: "off",
showGrandTotals: "off"
}
}
},
})
function customizeCellFunction(cell, data) {
if (
data &&
data.measure &&
data.type == "value" &&
data.measure.name == "originalQty"
) {
cell.addClass("highlighted-static")
}
}
function getData() {
return [
{
product: "A02V4N",
order: "000062",
originalQty: 2,
qty: 2,
},
{
product: "A02V6N",
order: "000062",
originalQty: 8,
qty: 8,
},
{
product: "A02V4N",
order: "000063",
originalQty: 2,
qty: 9,
},
{
product: "A02V6N",
order: "000063",
originalQty: 9,
qty: 9,
},
{
product: "A02V4N",
order: "000066",
originalQty: 1,
qty: 1,
},
{
product: "A02V6N",
order: "000066",
originalQty: 0,
qty: 0,
},
]
}