dataloaded, loadingdata, dataerror

Events

by Flexmonster Pivot Table

HTML

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

<div>
  <p>
    Click the <b>Load data</b> button to trigger the
    <code>loadingdata</code> event.
  </p>
  <p>
    After successfully loading the data, the <code>dataloaded</code> event is
    triggered and outputs the message under the component.
  </p>
  <p>
    If there are any issues when loading the data, the
    <code>dataerror</code> event is triggered and outputs the error message
    under the component.
  </p>
</div>

<button onclick="loadData()">Load data</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

var pivot = new Flexmonster({
	container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  height: 340
});

pivot.on('dataloaded', function () {
  showOutput('Data loaded!');
});

pivot.on('loadingdata', function () {
  showOutput('Loading data!');
});

pivot.on('dataerror', function (e) {
  showOutput('Error with data!' + e.error);
});

function loadData() {
  pivot.connectTo({
  	filename: "data/data.csv"
    })
}

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