Custom contextmenu

The following example customize the spreadsheet contextmenu removing the copy and paste options.



Source code

<html>
<script src="https://jspreadsheet.com/v7/jspreadsheet.js"></script>
<script src="https://jsuites.net/v4/jsuites.js"></script>
<link rel="stylesheet" href="https://jspreadsheet.com/v7/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://jsuites.net/v4/jsuites.css" type="text/css" />

<div id="spreadsheet"></div>

<script>
var data1 = [
    ['US', 'Cheese', '2019-02-12'],
    ['CA', 'Apples', '2019-03-01'],
    ['CA', 'Carrots', '2018-11-10'],
    ['BR', 'Oranges', '2019-01-12'],
];

mySpreadsheet = jspreadsheet(document.getElementById('spreadsheet'), {
    data: data1,
    columns: [
        { type: 'dropdown', url:'/jspreadsheet/countries', width:200, },
        { type: 'text', width:200, },
        { type: 'calendar', width:100, }
     ],
     allowComments: true,
     contextMenu: function(obj, x, y, e) {
         var items = [];

         if (x == null && y == null) {
             if (e.target.parentNode && e.target.tagName == 'DIV' && e.target.parentNode.classList.contains('jtabs-headers')) {
                 items.push({
                     title: obj.options.text.renameThisWorksheet,
                     onclick: function() {
                         var newName = prompt(obj.options.text.renameThisWorksheet, e.target.innerText);
                         if (newName) {
                             obj.renameWorksheet(e.target, newName);
                         }
                     }
                 });
             }
         } else {
             if (y == null) {
                 // Insert a new column
                 if (obj.options.allowInsertColumn == true) {
                     items.push({
                         title:obj.options.text.insertANewColumnBefore,
                         onclick:function() {
                             obj.insertColumn(1, parseInt(x), 1);
                         }
                     });
                 }

                 if (obj.options.allowInsertColumn == true) {
                     items.push({
                         title:obj.options.text.insertANewColumnAfter,
                         onclick:function() {
                             obj.insertColumn(1, parseInt(x), 0);
                         }
                     });
                 }
             } else {
                 // Insert new row
                 if (obj.options.allowInsertRow == true) {
                     items.push({
                         title:obj.options.text.insertANewRowBefore,
                         onclick:function() {
                             obj.insertRow(1, parseInt(y), 1);
                         }
                     });

                     items.push({
                         title:obj.options.text.insertANewRowAfter,
                         onclick:function() {
                             obj.insertRow(1, parseInt(y));
                         }
                     });
                 }
             }

             // Line
             items.push({ type:'line' });

             // Save
             if (obj.options.allowExport) {
                 items.push({
                     title: obj.options.text.saveAs,
                     shortcut: 'Ctrl + S',
                     onclick: function () {
                         obj.download();
                     }
                 });
             }

             // About
             if (obj.options.about) {
                 items.push({
                     title:obj.options.text.about,
                     onclick:function() {
                         alert(obj.options.about);
                     }
                 });
             }
         }

         return items;
     },
     license: 'NDc4ZDc3NWJiNjIzNzU4MTVmNjA4MjdlYjk1MjlmZDZiYzk4MWM3ZmM2OTdiZDczOWQ2MGRkZjdhNTc4ODExNmMyMDZkZDIwNzExYzJmM2EwOTBiYWUxM2M0NGY1YzNiZmVmZTY1OGY5OWI2ZDg2NDMyNjgwOTFhZGQ2MzVlYmEsZXlKdVlXMWxJam9pY0dGMWJDNW9iMlJsYkNJc0ltUmhkR1VpT2pFMk5EY3pPRGc0TURBc0ltUnZiV0ZwYmlJNld5SnFjMmhsYkd3dWJtVjBJaXdpWTI5a1pYTmhibVJpYjNndVkyOXRJaXdpYW5Od2NtVmhaSE5vWldWMExtTnZiU0lzSW1OellpNWhjSEFpTENKalpIQnVMbWx2SWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXlJbjA9',
});
</script>
</html>