Events for tracking report loading

Events

by Flexmonster Pivot Table

HTML

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

<div>
  <p>
    Click the <b>Open The Report</b> button to trigger the
    <code>loadingreportfile</code> event.
  </p>
  <p>
    After successfully loading the report, the
    <code>reportfilecancelled</code> event is triggered and outputs the message
    under the component.
  </p>
  <p>
    If there are any issues when loading the report, the
    <code>reportfileerror</code> event is triggered and outputs the error
    message under the component.
  </p>
</div>

<button onclick="openReport()">Open the report</button>

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

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

CSS

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

JavaScript

var pivot = new Flexmonster({
	container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  height: 350,
  report: {
    dataSource: {
      data: getData()
    }
  }
});

let outputInitialized = false;

function showOutput(content) {
  var log = "[" + (new Date()).toLocaleTimeString('en-US') + "] " + content;
  var outputElement = document.getElementById("output");
  if (!outputInitialized) {
    outputElement.innerText = '';
    outputInitialized = true;
  }
  outputElement.innerText += log + "\n";
  outputElement.scrollTop = outputElement.scrollHeight;
}

pivot.on('loadingreportfile', function () {
  showOutput('Loading report file!');
});
pivot.on('reportfileerror', function () {
  showOutput('Report file error!');
});
pivot.on('reportfilecancelled', function () {
  showOutput('Opening of report file was cancelled!');
});

function openReport() {
  pivot.open();
}

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
  }];
}