datafilecancelled

Events

by Flexmonster Pivot Table

HTML

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

<p>
  Click <b>Connect</b> &gt; <b>To local JSON</b> on the Toolbar. Select the report
  you want to load and click the <b>Cancel</b> button in the Open file dialog.
  As a result, the <code>datafilecancelled</code> event is triggered and outputs
  message under the component.
</p>

<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,
  beforetoolbarcreated: customizeToolbar
});

pivot.on('datafilecancelled', function () {
  showOutput('Data file cancelled!');
});

// click Cancel button in Open file dialog
function updateData() {
  pivot.connectTo({
    type: 'csv',
    browseForFile: true
  })
}

function customizeToolbar(toolbar) {
  let tabs = toolbar.getTabs();
  toolbar.getTabs = function() {
    // Keep only the "Connect" tab
    let connectTab = tabs.find(tab => tab.id == "fm-tab-connect");
    

    // Modify the dropdown menu of the "Connect" tab
 		connectTab.menu = [
		      {
		        id: "fm-tab-connect-local-json",
		        title: "Connect to local JSON",
		        handler: () => {
		          pivot.connectTo({
		            type: 'json',
		            browseForFile: true
		          })
		        },
		        icon: this.icons.open_local
		      }
		    ];


    // Return only the modified "Connect" tab
    return [connectTab];
  }
}

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