Handsontable example

by aszymanski

HTML

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.css">

<div id="example1" class="hot handsontable htRowHeaders htColumnHeaders" style="height: 320px; overflow: hidden; width: 100%;" data-originalstyle="height: 320px; overflow: hidden; width: 100%;"></div>
<div class="tooltip" style="visibility: hidden"></div>

CSS

.tooltip {
  height: 30px;
  color: grey;
  background: #fff;
  border: 2px solid #dedede;
  line-height: 30px;
  margin: 0 10px;
  box-shadow: 2px 2px 5px #ddd;
  z-index: 200;
}

JavaScript

const tooltip = document.querySelector('.tooltip');
  const example = document.getElementById('example1');
  
  const hot = new Handsontable(example, {
    data: Handsontable.helper.createSpreadsheetData(1000, 1000),
    colWidths: 100,
    width: '100%',
    height: 320,
    rowHeights: 23,
    rowHeaders: true,
    colHeaders: true,
    afterOnCellMouseOver: function(e, coords, TD) {
      if (coords.row < 0) {
        tooltip.style.visibility = 'visible';
        tooltip.innerHTML = `header for columns index <b>${coords.col}</b>`;
        tooltip.style.position = 'absolute';
        tooltip.style.top = '0px';
        tooltip.style.padding = '5px';
        tooltip.style.left = `${TD.getBoundingClientRect().x}px`;
      }
    },
  });