JSFiddle - React, Tailwind, and code Playground

Other

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div id="wrapper">
  <!--add your custom pop-up-->
  <div id="DrillThrough">
    <div class='popup-title'>
      <h3>Custom Details window</h3>
      <button id="popup-close-button" onclick="closePopup()">Close</button>
    </div>
    <div id="data"></div>
  </div>
  <div id="pivot-container"></div>
</div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);
#wrapper {
  height: 600px;
  position: relative;
}


#DrillThrough {
  position: absolute;
  inset: 0 0 0 0;
  margin: auto;
  min-width: 400px;
  width: 60%;
  height: 400px;
  z-index: 3;
  background: white;
  padding: 15px;
  display: none;
  border: 1px solid #d5d5d5;
  box-shadow: 0 0 20px rgb(0 0 0 / 10%);
}

#data {
  max-height: 300px;
  overflow: scroll;
  padding: 24px;
  overflow-y: scroll;
  background: rgba(242, 242, 242, 1);
  border-radius: 8px;
  font-family: Menlo, Monaco, "Courier New", Courier, monospace;
  font-size: 16px;
  white-space: pre;

}
.popup-title{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
#popup-close-button {
  user-select: none;
  font: inherit;
  transition: none;
  border-collapse: collapse;
  border-spacing: 0;
  font-family: Arial, sans-serif;
  margin: 0;
  text-shadow: none;
  line-height: normal;
  box-sizing: border-box;
  text-transform: uppercase;
  position: relative;
  outline: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  display: inline-block;
  vertical-align: top;
  font-size: 14px;
  font-weight: bold;
  padding: 10px 12px;
  letter-spacing: 0.5px;
  min-width: 90px;
  border: 1px solid #555;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  color: #fff;
  background: #555;
  margin-right: 20px;
  height: 38px;
}

JavaScript

const pivot = new Flexmonster({
  container: '#pivot-container',
  componentFolder: 'https://cdn.flexmonster.com/',
  height: 300,
  celldoubleclick: customDrillThrough, //add custom handler for double-click
  report: {
    options: {
      drillThrough: false, // disable default drill-through
    },
    dataSource: {
      data: getData(),
      mapping: {
        accountId: {
          type: 'id',
        },
      },
    },
    slice: {
      rows: [
        {
          uniqueName: 'status',
        },
      ],
      columns: [
        {
          uniqueName: '[Measures]',
        },
      ],
      measures: [
        {
          uniqueName: 'purchases',
        },
      ],
    },
  },
});

const drillThroughPopup = document.getElementById('DrillThrough');
const drillThroughData = document.getElementById('data');

function customDrillThrough(cell) {
  // sample approach to extract detailed data
  // you may add your own functionality instead
  const ids = cell.recordId;
  const records = [];
  for (let i = 0; i < ids.length; i++) {
    records.push(getRecord(ids[i]));
  }
  openDrillThrough(JSON.stringify(records, null, 2));
}

function getRecord(id) {
  const data = getData();
  for (let i = 0; i < data.length; i++) {
    if (data[i].accountId === id) {
      return data[i];
    }
  }
  return null;
}

function openDrillThrough(data) {
  console.log(data);
  drillThroughData.innerHTML = data;
  drillThroughPopup.style.display = 'block';
}

function closePopup() {
  drillThroughData.innerHTML = '';
  drillThroughPopup.style.display = 'none';
}

function getData() {
  return [
    {
      accountId: 23,
      name: 'My test acccount XYZ',
      status: 'Active',
      address: '321 Michigan Sq., #55',
      purchases: 210,
    },
    {
      accountId: 32,
      name: 'My test acccount ABC',
      status: 'Inactive',
      address: '123 Oxford Av., #23',
      purchases: 932,
...