API call off for removing JS handlers for specified event

Events

by Flexmonster Pivot Table

HTML

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

<p>
  Add a handler and click a cell to trigger the <code>cellclick</code> event
  that outputs info about the cell under the component.
</p>

<button onclick="addEvent()">Add handler for 'cellclick' event</button>
<button onclick="removeEvent()">
  Remove specified handler for 'cellclick' event
</button>
<button onclick="removeAllEvents()">
  Remove all handlers for 'cellclick' event
</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/",
  height: 290,
  report: {
    dataSource: {
    	data: getData()
    }
  }
});

var onCellClick = function(result) {
    showOutput(
        "Clicked a cell - row: " +
        result.rowIndex +
        ", column: " +
        result.columnIndex +
        ", label: " +
        result.label
    );
};

function addEvent() {
  //add handler for 'cellclick' event
  pivot.on('cellclick', onCellClick);
  console.log('The cellclick event was added');
}

function removeEvent() {
  //remove specified handler for event
  pivot.off('cellclick', onCellClick);
  console.log('The specified handler for cellclick event was removed');
}
function removeAllEvents() {
  //remove all handlers for 'cellclick' event
  pivot.off('cellclick');
  console.log('All handlers for cellclick event were removed');
}

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


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