Disable command Cut in SpreadJS 14

Posted by: thanh.minh.le on 23 February 2023, 4:53 am EST

    • Post Options:
    • Link

    Posted 23 February 2023, 4:53 am EST

    Hello,

    Our goal is to disable the cut command in SpreadJS. We have successfully disabled the “ctrl + x” shortcut using the following code:

    spread.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.x, true, false, false, false)

    However, we’ve noticed that when a user tries to use “ctrl + x,” they can still paste the cut cell’s content into another cell. Is there a way to prevent this behavior?

    Regards,

    Thanh

  • Posted 24 February 2023, 6:45 am EST

    Hello,

    You can disable the ctrl+x (cut) command in SpreadJS by creating a custom command and bind it with Ctrl + x keys. This custom command does not do anything and overrides the default (cut) command. You can register the custom command with commandManager.register() method.

    Please note that when pressing ctrl + v, the value is pasted from external clipboard. External clipboard is given preference over internal clipboard on pressing ctrl + v. To explicitly paste values from internal clipboard, you can use context menu of spreadsheet.

    To better understand please refer to below code snippet and attached snippet

    [code]let commandManager = spread.commandManager();

    // creates a custom command

    let command = {

    canUndo: false,

    execute: function (context, options, isUndo) {

    return true;

    }

    }

    // adds the custom command to command manager

    commandManager.register(‘custom’, command, GC.Spread.Commands.Key.x, true, false, false, false);[/code]

    Sample: https://jscodemine.grapecity.com/share/0L4gWmDsNEOBGjj6cNYNfw/?defaultOpen={“OpenedFileName”%3A[“%2Findex.html”%2C"%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    Please let us know if the issue still persists.

    Doc reference

    CommandManager class: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Commands.CommandManager#class-commandmanager

    commandManager.register(): https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Commands.CommandManager#register

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels