Loading data asynchronously with Ajax

Other

by Flexmonster Pivot Table

HTML

<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div id="pivot-container"></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/",
  width: "100%",
  height: 430,
  toolbar: true,
  reportcomplete: reportComplete
});


function reportComplete() {
  pivot.off("reportcomplete");
  $.ajax({
    type: "GET",
    url: 'https://cdn.flexmonster.com/data/data.json',
    dataType: "text",
    success: function(data) {
      var json = JSON.parse(data);
      pivot.setReport({
        dataSource: {
          data: json
        }
      });
    },
    error: function(err) {
      console.error(err);
    }
  });
}