React

by monamrouche

HTML

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

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

React

import React, { useRef, useEffect } from 'react';
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';

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

const hot = new Handsontable(container, {
  licenseKey: 'non-commercial-and-evaluation',
  data: [
    ['', '', '', '', ''],
    ['', '', '', '', ''],
    ['', '', '', '', ''],
    [null]
  ],
   undo:true,
   columns: [
          { renderer: 'text' },
          { renderer: 'text' },
          { renderer: 'text' },
          {
            validator: function (value, callback) {  
              if(!isNaN(Number(value))){
                callback(true)
              } else {
                callback(false)
              }
          }
          },
          { renderer: 'text' }
        ],

 columnSummary: [
          {
            type: 'sum',
            destinationRow: 3,
            destinationColumn: 3,
            forceNumeric: true
          },
  
        ]
});

hot.addHook('afterChange', (changes, source) => {
 // i jsut add this afterChange hook to help you catch the issue !! maybe it's helpful !!!
   console.log(source)
   console.log(changes)
   console.log(hot.undoRedo.doneActions)
   console.log(hot.undoRedo.undoneActions)
})