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>

<div class="output" id="output">Output will appear here</div>

CSS

.output {
  width: 80%;
  height: 300px;
  margin-left: auto;
  margin-right: auto;
  padding: 20px;
  background: rgba(242, 242, 242, 1);
  font-family: Menlo, Monaco, "Courier New", Courier, monospace;
  white-space: pre;
  font-size: 16px;
  font-weight: 400;
  overflow-y: scroll;
  margin-top: 20px;
}

JavaScript

let pivot = new Flexmonster({
  container: "pivotContainer",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      data: getData(),
      mapping: {
        id: {
          type: "id"
        },
        data_type: {
          type: "property",
          hierarchy: "title"
        }
      }
    },
    options: {
    	drillThrough: false
    }
  }
});

flexmonster.on("celldoubleclick", handler);

function handler(cell) {
  let output = "";
  output += `IDs: ${JSON.stringify(cell.recordId)}\n`;
  if (cell.member) {
    output += `PROPERTY: ${JSON.stringify(cell.member.properties)}`
  } else {
  	output += "PROPERTIES:\n"
  	for(let row of cell.rows) {
    	if(!row.properties) continue;
    	output += `${JSON.stringify(row.properties)}\n`
    }
  	for(let row of cell.columns) {
    	if(!row.properties) continue;
    	output += `${JSON.stringify(row.properties)}\n`
    }
  }
  showOutput(output);
}

function getData() {
  return [{
      'id': 1,
      'data_type': 'furniture',
      'title': 'large red chair',
      'category': 'chair'
    },
    {
      'id': 2,
      'data_type': 'furniture',
      'title': 'small green chair',
      'category': 'chair'
    },
    {
      'id': 3,
      'data_type': 'food',
      'title': 'large red apple',
      'category': 'fruit'
    },
    {
      'id': 4,
      'data_type': 'food',
      'title': 'small green chair',
      'category': 'fruit'
    }
  ]
}

function showOutput(content) {
  document.getElementById("output").innerText = content;
}