Handsontable example

by handsoncode

HTML

<div id="example3" class="hot handsontable htRowHeaders htColumnHeaders"></div>

CSS

</style><!-- Ugly Hack due to jsFiddle issue --> <script src="https://docs.handsontable.com/pro/bower_components/handsontable-pro/dist/handsontable.full.min.js"></script> <link type="text/css" rel="stylesheet" href="https://docs.handsontable.com/pro/bower_components/handsontable-pro/dist/handsontable.full.min.css">

JavaScript

document.addEventListener("DOMContentLoaded", function() {

  function getData() {
    return [
      ['', 'Kia', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
      ['2012', 10, 11, 12, 13, 15, 16],
      ['2013', 10, 11, 12, 13, 15, 16],
      ['2014', 10, 11, 12, 13, 15, 16],
      ['2015', 10, 11, 12, 13, 15, 16],
      ['2016', 10, 11, 12, 13, 15, 16]
    ];
  }

  var
    example3 = document.getElementById('example3'),
    settings3,
    hot3;

  settings3 = {
    data: getData(),
    rowHeaders: true,
    colHeaders: true
  };
  hot3 = new Handsontable(example3, settings3);

  hot3.updateSettings({
    contextMenu: {
      items: {
        "row_above": {
          name: 'Add 5 rows above',
          callback: function(key, options) {
            hot3.alter('insert_row', hot3.getSelected()[0], 5)
          }
        },
        "row_below": {
          name: 'Add 5 rows below',
          callback: function(key, options) {
            hot3.alter('insert_row', hot3.getSelected()[0]+1, 5)
          }
        }
      }
    }
  })



});