Is there a way to disable the insert/remove row and column (Contextual menu)?

Posted by: fahmii.bensalah on 16 September 2018, 10:53 pm EST

    • Post Options:
    • Link

    Posted 16 September 2018, 10:53 pm EST

    Hi,

    I would like to disable the insert and delete events of rows and columns from the sheet contextuel menu.

    Thanks,

  • Posted 17 September 2018, 9:15 pm EST

    Hello,

    You may go through this documentation link which shows how to add/remove custom menu options in a context menu:-

    http://help.grapecity.com/spread/SpreadSheets11/webframe.html#UsingtheContextMenu.html

    You can customize your context menu further as per your need. To get the cell index of clicked cell you can use the code as given here:-

    http://sphelp.grapecity.com/webhelp/SpreadSheets10/webframe.html#scxyindex.html

    The only difference is that the code in that page is for left-clicking, so it would need to be changed a little to something like this for right-clicking:-

    https://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery

    Hope it helps.

    Thanks,

    Reeva

  • Posted 9 October 2019, 7:07 am EST

    ***For future help :slight_smile:

    this.spread.contextMenu.menuData = this.spread.contextMenu.menuData.filter(

    i => !(i.text === ‘Insert’ || i.text === ‘Delete’));

    ===Angular===

  • Posted 15 August 2020, 1:39 am EST

    Hi,

    We are looking into this query, we shall update you soon

  • Posted 16 August 2020, 5:47 pm EST

    Hi Vinayak,

    You may override the OnOpenMenu method of the context menu and return true for the cell(s) for which you need to disable the context menu. Please refer to the following code snippet and attached sample which demonstrates the same.

    function ContextMenu() {}
    ContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(spread);
    ContextMenu.prototype.onOpenMenu = function (
      menuData,
      itemsDataForShown,
      hitInfo,
      spread
    ) {
      let sheetInfo = hitInfo.worksheetHitInfo;
      let sel = spread.getActiveSheet().getSelections();
      if (sheetInfo.hitTestType === 3) {
        for (let i = 0; i < sel.length; i++) {
          if (
            (sheetInfo.row === 4 && sheetInfo.col === 4) ||
            (sel[i].row <= 3 &&
              sel[i].row + sel[i].rowCount - 1 >= 3 &&
              sel[i].col <= 3 &&
              sel[i].col + sel[i].colCount - 1 >= 3)
          ) {
            return true;
          }
        }
      }
      return false;
    };
    var contextMenu = new ContextMenu();
    spread.contextMenu = contextMenu;
    

    sample: https://codesandbox.io/s/hungry-stonebraker-5ebsk?file=/src/index.js

    API References:

    onOpenMenu: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.ContextMenu.ContextMenu~onOpenMenu.html

    Regards

  • Posted 17 August 2020, 6:45 am EST

    allowContextMenu disables context menu. But is there any way through which we can disable context menu conditionally for some specific rows and enable for other rows.

    I am trying to implement this in Angular 7

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels