JSFiddle - React, Tailwind, and code Playground

by Flexmonster Pivot Table

HTML

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

<div id="pivot-container"></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

//Replace this endpoint with your authorization service
fetch('https://olap.flexmonster.com:9500', {
    //if needed, add additional configurations
    method: 'GET'
  })
  .then((data) => {
  
    //Retreive the token from response
    let authtoken = toString(data.token);

    //Initialize the component with customizeAPIRequest
    let pivot = new Flexmonster({
      container: "pivot-container",
      componentFolder: "https://cdn.flexmonster.com/",
      width: "100%",
      height: 300,
      customizeAPIRequest: (req) => {
        req.requestHeaders = {
          AuthToken: authtoken,
        };
        showOutput(JSON.stringify(req, null, 2));
        return req;
      },
      report: {
        dataSource: {
          type: "api",
          url: "https://olap.flexmonster.com:9500",
          index: "fm-product-sales"
        },
        slice: {
          rows: [{
            uniqueName: "Category"
          }],
          columns: [{
            uniqueName: "[Measures]"
          }],
          measures: [{
            uniqueName: "Price"
          }]
        }
      }
    });
  });
  
//If the token is expired, you can reload it and resend the request to your custom API data source   
flexmonster.on('unauthorizederror', function (callbackHandler) {
    //Replace this endpoint with your authorization service
fetch('https://olap.flexmonster.com:9500', {
    method: 'GET'
  })
  .then((data) => {
    //Retreive the token from response
    let authtoken = toString(data.token);
        callbackHandler({
        requestHeaders: {
            AuthToken: authtoken
        }
    });
  });
 
});

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