Handsontable example
HTML
<script src="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.css" />
<script src="https://unpkg.com/sheetclip"></script>
<div id="example3" class="hot "></div>
JavaScript
const container = document.querySelector('#example3');
const hot = new Handsontable(container, {
data: [
['', 'Tesla', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
['2017', 10, 11, 12, 13, 15, 16],
['2018', 10, 11, 12, 13, 15, 16],
['2019', 10, 11, 12, 13, 15, 16],
['2020', 10, 11, 12, 13, 15, 16],
['2021', 10, 11, 12, 13, 15, 16]
],
rowHeaders: true,
colHeaders: true,
licenseKey: 'non-commercial-and-evaluation',
height: 'auto',
});
let clipboardCache = '';
let sheetclip = new SheetClip();
const copyPastePlugin = hot.getPlugin('CopyPaste')
hot.updateSettings({
afterCopy: function(changes) {
clipboardCache = sheetclip.stringify(changes);
},
afterCut: function(changes) {
clipboardCache = sheetclip.stringify(changes);
},
beforePaste: function(arr){
arr.pop()
},
afterPaste: function(changes) {
clipboardCache = sheetclip.stringify(changes);
},
contextMenu: [
'copy',
'cut',
{
key: 'paste',
name: 'Paste',
disabled: function() {
return clipboardCache.length === 0;
},
callback: function() {
this.listen();
copyPastePlugin.paste(clipboardCache);
}
}
],
})