print and export events

Events

by Flexmonster Pivot Table

HTML

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

<div>
  <p>
    Click the <b>Print</b> button to trigger the <code>printstart</code> event
    that outputs the message under the component. When the OS print manager is
    closed, the <code>printcomplete</code> event is triggered.
  </p>

  <p>
    Click the <b>Export</b> button to trigger the <code>exportstart</code> event
    that outputs the message under the component. When the export is complete,
    the <code>exportcomplete</code> event is triggered.
  </p>
</div>

<button onclick="printGrid()">Print</button>
<button onclick="exportGrid()">Export</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/",
  width: "100%",
  height: 290,
  report: {
    dataSource: { data: getData() }
  }
});
function printGrid() {
  pivot.print();
}
function exportGrid() {
  pivot.exportTo('csv', {filename : 'flexmonster.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;
}

pivot.on('exportstart', function () {
    showOutput('Exporting started!');
});
pivot.on('exportcomplete', function () {
    showOutput('Exporting completed!');
});
pivot.on('printstart', function () {
    showOutput('Printing started!');
});
pivot.on('printcomplete', function () {
    showOutput('Printing completed!');
});

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",
   ...