Flexmonster - Limit number of fields in rows

by Ian Sadovy

HTML

<script src="https://s3.amazonaws.com/flexmonster/2.2/flexmonster.js"></script>
<div id="pivot-content"></div>

JavaScript

flexmonster.embedPivotComponent("https://s3.amazonaws.com/flexmonster/2.2/", "pivot-content", "100%", "600", {
  licenseKey: "Z53G-1T1WC3-1V1M-0L12-2M0A-1233-1I0Y-2Y2Q-1903-322S-0T2C-1I",
  configuratorActive: false,
  jsReportChangeHandler: onReportChange,
  data: getData()
}, true);

function onReportChange() {
  // get rows and check if it fits the limit
  var rows = flexmonster.getRows();
  if (rows.length > 2) {
    // show warning
    alert("Warning: you cannot select more than 2 rows.");
    // set the number of rows to 2
    // and keep other fields as is
    var slice = {
      rows: rows.slice(0, 2),
      columns: flexmonster.getColumns(),
      pages: flexmonster.getPages(),
      measures: flexmonster.getMeasures()
    };
    flexmonster.runQuery(slice);
  }
}

function getData() {
  return [{
    "Color": "green",
    "M": "September",
    "W": "Wed",
    "country": "Canada",
    "state": "Ontario",
    "city": "Toronto",
    "Price": 174,
    "Quantity": 22
  }, {
    "Color": "red",
    "M": "March",
    "W": "Mon",
    "Time": "1000",
    "country": "USA",
    "state": "California",
    "city": "Los Angeles",
    "Price": 1664,
    "Quantity": 19
  }, {
    "Color": "red",
    "M": "January",
    "W": "Mon",
    "country": "Canada",
    "state": "Quebec",
    "city": "Montreal",
    "Price": 1190,
    "Quantity": 292
  }, {
    "Color": "green",
    "D": "04/08/2014",
    "M": "August",
    "W": "Fri",
    "Time": "1000",
    "country": "USA",
    "state": "California",
    "city": "Los Angeles",
    "Price": 1222,
    "Quantity": 730
  }, {
    "Color": "white",
    "M": "March",
    "W": "Wed",
    "country": "USA",
    "state": "California",
    "city": "Los Angeles",
    "Price": 7941,
    "Quantity": 73
  }, {
    "Color": "red",
    "M": "August",
    "W": "Wed",
    "country": "Canada",
    "state": "Ontario",
    "city": "Toronto",
    "Price": 6829,
    "Quantity": 19
  }, {
    "Color": "green",
    "M": "January",
    "W": "Wed",
   ...