Passing parameters to keyboard shortcut callback

Posted by: tadekunle on 8 November 2021, 10:19 am EST

    • Post Options:
    • Link

    Posted 8 November 2021, 10:19 am EST

    Hello,

    I am trying to define custom keyboard shortcuts to be used in spreadjs. I went through this example https://www.grapecity.com/blogs/spread-sheets-excel-navigation and i see the callback functions have parameters in their definition but i dont see where the parameters are passed when the command is being registered. I was wondering how the passing of parameters works with the callback functions of keyboard shortcuts and if it is possible for me to pass in an object to the callback function.

    I also tried to define keyboard shortcuts for certain keys like the backslash (alt + /), equals (alt + =) and period (alt + .) keys but they weren’t working. Is it possible for me to have special keys like i mentioned above used in keyboard shortcuts?

    Thanks for your help

  • Posted 9 November 2021, 4:59 am EST

    Hi,

    When using the keyboard shortcuts, SpreadJS calls the registered execute callback automatically by passing the correct callback parameter options. The options object includes the sheetName on which action is invoked.

    However, it is possible to pass custom options when we explicitly call the command using the execute method.

    API reference:

    https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Commands.CommandManager~execute.html

    I’ve prepared a sample to demonstrate how you could register alt + = combination for custom action. Please refer to the same and let me know if you face any issues:

    https://jscodemine.grapecity.com/share/vdYi0cbQjUqQ5yexHIrQFg/

    Regards

  • Posted 10 November 2021, 8:53 am EST

    Hi,

    Thanks for the alt + = demo, that worked.

    However concerning the first issue I am still unclear of the instructions. Right now I am trying to register a callback function to a custom keyboard shortcut by calling the setShortcutKey() and registerCommand() methods like so

    
    commandManager.register('altR', this.sampleShortcutAlertUser); 
    commandManager.setShortcutKey(
    			'altR',
    			KeyBindings.r,
    			false,
    			false,
    			true,
    			false
    		);
    
    

    where this.sampleAlertUser is the callback function that I want to pass parameters into. How can I pass my custom parameters into this callback function that will be triggered when a keyboard shortcut is pressed?

    Thank you.

  • Posted 11 November 2021, 9:39 pm EST

    Hi,

    We are sorry but we could not pass parameters to shortcutkeys callback however if the values are not getting changed you could store the values as closure inside the execute function.

    Regards

    Avinash

Need extra support?

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

Learn More

Forum Channels