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: {
callback: function (key, options) {
if (key === 'about') {
setTimeout(function () {
// timeout is used to make sure the menu collapsed before alert is shown
alert("This is a context menu with default and custom options mixed");
}, 100);
}
},
items: {
"row_above": {
disabled: function () {
// if first row, disable this option
return hot3.getSelected()[0] === 0;
}
},
"row_below": {},
"hsep1": "---------",
"remove_row": {
name: 'Remove this row, ok?',
disabled: function () {
// if first row, disable this option
return hot3.getSelected()[0] === 0
}
},
"hsep2": "---------",
"about": {name: 'About this menu'},
"testsubmenu1": {
key: "submenu",
name: "submenu",
"submenu": {
"items": [
{
key: "submenu:1",
"name": "sub1",
callback: function(key, options) {}
}, {
key: "submenu:2",
"name": "sub2",
callback: function(key, options) {
console.log("clicked" + key);
}
}, {
key: "submenu:3",
"name": "sub3",
callback: function(key, options) {
...