Disable arrow key events while in editing mode of a cell

Posted by: gerald on 21 September 2020, 3:12 pm EST

  • Posted 21 September 2020, 3:12 pm EST

    Is it possible that for certain cases I can prevent the sheet from navigating through cells with the arrow keys?

    The use case is: When in EDITING mode of a cell I want to prevent that when pressing arrow down/up keys the user leaves the cell and navigates somewhere else because I want to do something else with the key-event.

    best regards,
    Gerald
  • Marked as Answer

    Replied 22 September 2020, 12:40 am EST

    Hi Gerald,

    You may override isReservedKey method for the required functionality. Please refer to the following code snippet and the attached sample demonstrating the same.

    let oldFunction = GC.Spread.Sheets.CellTypes.Text.prototype.isReservedKey;
    GC.Spread.Sheets.CellTypes.Text.prototype.isReservedKey = function (
    e,
    context
    ) {
    //cell type handle tab key by itself

    if (
    e.keyCode === GC.Spread.Commands.Key.up &&
    !e.ctrlKey &&
    !e.shiftKey &&
    !e.altKey
    ){
    //Do some thing
    alert("Up key executed")
    return true;
    }
    else {
    oldFunction.apply(this, arguments);
    }
    };


    sample: https://codesandbox.io/s/gracious-browser-ijz0d?file=/src/index.js

    API References:

    isReservedKey: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.CellTypes.Base~isReservedKey.html

    Regards
    Avinash
  • Replied 27 September 2020, 6:27 pm EST

    Perfect, thank you!
Need extra support?

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

Learn More

Forum Channels