How to disable cut/past in spreadView

Posted by: wmeng on 1 February 2019, 12:58 pm EST

  • Posted 1 February 2019, 12:58 pm EST

    How I can disable the short cut keys ctrl+x/ ctrl+v for cut/paste in spread view?
  • Marked as Answer

    Replied 3 February 2019, 10:11 pm EST

    Hi,
    SpreadView allows cut/paste only when the SpreadView is in edit mode.
    SpreadView cut/paste can be prevented by handling the cut/paste event for SpreadView hostElement.
    Please refer to the following code snippet for the same:
    // prevent cut/paste for SpreadView Editor
    var spreadView=document.getElementById("grid1");
    spreadView.addEventListener("cut",function(e){
    e.preventDefault();
    },true);
    spreadView.addEventListener("paste",function(e){
    e.preventDefault();
    },true);


    Further, the spread view, enter in Edit mode on pressing Ctrl+x/v key combiniation, if you would like to prevent this too, you should handle the keydown event for document and check the if the target is spreadview. Please refer to the following code snippet:
    // prevent SpreadView to enter edit mode on pressing Ctrl+X/v
    document.addEventListener("keydown",function(e){
    if(e.ctrlKey && (e.key=="x"||e.key=="v")
    && document.activeElement === document.getElementById("grid1")){
    e.preventDefault();
    e.stopImmediatePropagation();
    e.stopPropagation();
    }
    },true);


    For reference, please find the attached sample.

    ~Manish

    SpreadView_Prevent_CutPaste.zip
Need extra support?

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

Learn More

Forum Channels