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>


<button onclick="greaterFilter(50)">
Discount amount > 50
</button>

<div id="pivot-container"></div>

JavaScript

new Flexmonster({
  container: "#pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
  height: 400,
  report: {
    "dataSource": {
      "type": "microsoft analysis services",
      "proxyUrl": "https://olap.flexmonster.com:8085/",
      "catalog": "Adventure Works DW Standard Edition",
      "cube": "Adventure Works",
      "binary": true
    },
    "slice": {
      "rows": [{
        "uniqueName": "[Geography].[City]"
      }],
      "columns": [{
        "uniqueName": "[Measures]"
      }],
      "measures": [{
        "uniqueName": "[Measures].[Discount Amount]"
      }]
    },
    "options": {
      "showMemberProperties": true
    },
    "version": "2.9.33",
    "creationDate": "2022-09-12T13:20:02.746Z"
  }
});

function greaterFilter(num) {
  let topCounter = 0;
  /*
  Use the getData API call to retrieve the raw data from the grid.
  NOTE: this approach iterates through the data loaded from the cube on the client's machine, so using it with big datasets will slow the performance.
  */
  flexmonster.getData({},
    (rawData) => {
      //Find how many values are bigger than "num", which will allow simulating the "Greater" filter with the "Top" filter
      topCounter = rawData.data.filter(obj => {
        /*
        r0 !== undefined - excludes grand total
        obj.v0 > num - checks if the value is greater than "num"
        (number after "v" stands for index of the measure in Measures[] array)
        */
        return obj.r0 !== undefined && obj.v0 > num;
      }).length;

    },
    (rawData) => {
       /* In this case, second callback function is not needed */
    }
  );
  
  /*Apply Top filter*/
  flexmonster.setFilter("[Geography].[City]", {
    "measure": {
      "uniqueName": "[Measures].[Discount Amount]",
      "aggregation": "none"
    },
    "query": {
      "top": topCounter
    }
  })

}