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

var pivot = new Flexmonster({
	container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  width: "100%",
  height: 430,
  toolbar: true,
  reportcomplete: onReportComplete,
  reportchange: onReportChange,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      columns: [{
        uniqueName: "Color"
      }],
      rows: [{
        uniqueName: "Country"
      }, {
        uniqueName: "[Measures]"
      }],
      measures: [{
        uniqueName: "Price",
        format: "currency"
      }, {
        uniqueName: "Discount",
        format: "currency"
      }],
    },
  }
});
function onFieldsChanged() {
	console.log("on fields changed");
  // put your code here
}

var slice = null;
function onReportComplete() {
  slice = pivot.getReport().slice;
}
function onReportChange() {
  setTimeout(function() {
    var newSlice = pivot.getReport().slice;
    if (isDifferent(slice, newSlice)) {
    	onFieldsChanged();
    }
    slice = newSlice;
  }, 1);
}
function isDifferent(s1, s2) {
	return isArrayDifferent(s1.pages, s2.pages)
  	|| isArrayDifferent(s1.rows, s2.rows)
    || isArrayDifferent(s1.columns, s2.columns)
    || isArrayDifferent(s1.measures, s2.measures);
}
function isArrayDifferent(a1, a2) {
	if (a1 == null && a2 == null) return false;
	if (a1 && !a2 || !a1 && a2) return true;
  if (a1.length != a2.length) return true;
  for (var i = 0; i < a1.length; i++) {
  	if (a1[i].uniqueName != a2[i].uniqueName) {
    	return true;
    }
  }
  return false;
}