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="pivotContainer"></div>

JavaScript

let pivot = new Flexmonster({
  container: "pivotContainer",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv"
    }
  }
});

flexmonster.customizeContextMenu(function(items, data, viewType) {
  if (Array.isArray(data)) {
		items.push({
    	label: '"baz" function',
      handler: () => {
        baz(data);
      }
    });
  } else {
    items.push({
      label: '"foo" function',
      handler: () => {
        foo(data);
      }
    });
    items.push({
      label: '"bar" function',
      handler: () => {
        bar(data);
      }
    });
  }
  return items;
});

function foo(cell) {
  alert(`"foo" function for the "${cell.rowIndex}-${cell.columnIndex}" cell was invoked`);
}

function bar(cell) {
  alert(`"bar" function for the "${cell.rowIndex}-${cell.columnIndex}" cell was invoked`);
}

function baz(cells) {
	let indexes = cells.reduce(function (arr, cell) {
  	arr.push(`${cell.rowIndex}-${cell.columnIndex}`);
    return arr;
  }, [])
  alert(`"bar" function for ${indexes} cells was invoked`);
}