Handsontable example

by handsoncode

HTML

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

<div id="example1" class="hot "></div>

JavaScript

const container = document.querySelector('#example1');

const hot = new Handsontable(container, {
  data: Handsontable.helper.createSpreadsheetData(10, 10),
  colHeaders: true,
  rowHeaders: true,
  licenseKey: 'non-commercial-and-evaluation',
  multiColumnSorting: {
    sortEmptyCells: false,
    indicator: true,
    headerAction: true,
    compareFunctionFactory: compareFunctionFactory,
  }
});

function compareFunctionFactory(sortOrder, columnMeta) {
  // implement your own comparator
  return function(value, nextValue) {
    if (value < nextValue) {
      return -1;
    }
    if (value > nextValue) {
      return 1;
    }

    return 0;
  };
};