API calls setTableSizes and getTableSizes

Other

by Flexmonster Pivot Table

HTML

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

<div>
  <p>
    Use the buttons below to set table sizes for the component or output
    information about them under the component.
  </p>
</div>

<button onclick="setTableSizes()">Set table sizes</button>
<button onclick="getTableSizes()">Get table sizes</button>

<div id="pivot-container">The component will appear here</div>

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

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  height: 300,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      rows: [{
        uniqueName: "Category"
      }],
      columns: [{
          uniqueName: "Country",
          filter: {
            exclude: [
              "country.[canada]",
              "country.[united kingdom]"
            ]
          }
        },
        {
          uniqueName: "[Measures]"
        }
      ],
      measures: [{
        uniqueName: "Price",
        aggregation: "sum"
      }]
    },
  }
});

function setTableSizes() {
  pivot.setTableSizes({
    columns: [{
        idx: 0,
        width: 160
      },
      {
        tuple: ["country.[germany]"],
        measure: {
          uniqueName: "Price",
          aggregation: "sum"
        },
        width: 160,
      }
    ],
    rows: [{
      idx: 0,
      height: 80
    },
    {
      tuple: ["category.[cars]"],
      height: 80
    }]
  });
}

function getTableSizes() {
  let tableSizes = pivot.getTableSizes();
  showOutput(JSON.stringify(tableSizes, null, 4));
}

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