JSFiddle - React, Tailwind, and code Playground

by Flexmonster Pivot Table

HTML

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

<div id="pivotContainer"></div>

CSS

body {
  font-family: sans-serif;
}

h3 {
  display: inline;
}

#wrapper {
  height: 600px;
  position: relative;
}

#field-list,
#filter-list {
  position: absolute;
  inset: 0 0 0 0;
  margin: auto;
  min-width: 300px;
  width: 40%;
  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%);
}

#fields,
#filters {
  margin-top: 30px;
  max-height: 300px;
  padding: 15px;
  overflow-y: scroll;
  border: 1px solid #d5d5d5;
}

#field-list-apply-button,
#filter-apply-button {
  float: right;
  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;
}

.field-item,
.fitler-item {
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.field-select,
.field-button,
.sigma-icon {
  margin-left: 10px;
}

.filter-checkbox {
  float: right;
  margin-left: auto;
}

.sigma-icon {
  font-weight: bold;
}

.field-name,
.filter-name {
  width: 150px;
  max-width: 150px;
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

JavaScript

let pivot = new Flexmonster({
  container: "pivotContainer",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    "dataSource": {
      "type": "api",
      "url": "https://olap.flexmonster.com:9500",
      "index": "fm-product-sales"
    }
  }
});

flexmonster.on("reportcomplete", validateReport);

function validateReport() {
  let slice = flexmonster.getReport().slice;
  if (!slice) return;

  let valid = true;
  let columns, rows;
  let count = {
    cols: 0,
    rows: 0
  }

  if (slice.columns) {
    columns = slice.columns.filter(field => {
      if (count.cols < 1) {
        count.cols++;
        return true;
      }
      if(field.uniqueName == "[Measures]") {
        return true;
      }
      valid = false;
      return false;
    });
  }

  if (slice.rows) {
    rows = slice.rows.filter(field => {
      if (count.rows < 1) {
        count.rows++;
        return true;
      }
      if(field.uniqueName == "[Measures]") {
        return true;
      }
      valid = false;
      return false;
    });
  }

  if (!valid) {
    flexmonster.alert({
      title: "Error - more than 1 field is selected to columns or rows",
      message: "Report was adjusted to match constraints",
      type: "error",
      buttons: [{
        label: "OK",
      }],
      blocking: false
    });
    slice.columns = columns;
    slice.rows = rows;
    flexmonster.runQuery(slice);
  }
}