Handsontable - get programmatically

by TigerAsks

HTML

<script src="https://handsontable.com/bower_components/handsontable/dist/handsontable.full.js"></script>
<link rel="stylesheet" href="https://handsontable.com/bower_components/handsontable/dist/handsontable.full.css">
<h2>Access table Programatically</h2>
<p>
Head to <a href="https://handsontable.com" target="_blank">handsontable.com</a> to learn more about Handsontable.
</p>

<input type = button value = "clear" onclick = "clearTable()">
<div id="container"></div>

CSS

body {   
  margin: 20px 30px;
  font-size: 13px;
  font-family: 'Open Sans', Helvetica, Arial;
}

a {
  color: #34A9DC;
  text-decoration: none;
}

p {
  margin: 5px 0 20px;
}

h2 {
  margin: 20px 0 0;
  font-size: 18px;
  font-weight: normal;
}

JavaScript

var data = function () {
  return Handsontable.helper.createSpreadsheetData(3, 3);
};

var container = document.getElementById('container');

var hot = new Handsontable(container, {
  data: data(),
  minSpareCols: 1,
  minSpareRows: 1,
  rowHeaders: true,
  colHeaders: true,
  contextMenu: true
});

container.handson = hot; //should happen in component constructor

function clearTable(){
	'use strict';
    //in this example, we want to call `hot.clear()` without actually using any of the declared variables
    let table = document.getElementById("container").handson;
    table.clear();
}