How to perform a Backspace function programatically in Edit mode?

Posted by: mobitahir on 8 November 2017, 6:47 pm EST

    • Post Options:
    • Link

    Posted 8 November 2017, 6:47 pm EST

    What i am trying to do is that while a cell is in edit mode i want to prevent default backspace action and perform a custom Backspace action programatically. I have written logic to achieve this but my code doesn’t work in edit mode:

    //BACKSPACE LOGIC:

                
    if (event.keyCode == 8) {
                    //event.preventDefault();
                    var sheet = spreads[spreadIndex].getActiveSheet();
                    var rowIndex = sheet.getActiveRowIndex();
                    var colIndex = sheet.getActiveColumnIndex();
                    var cellValue = sheet.getCell(rowIndex, colIndex).text();
                    sheet.getCell(rowIndex, colIndex).text(cellValue.slice(0, -2));
                }
    
    

    Please help.

  • Posted 10 November 2017, 3:01 am EST

    Hello,

    You can use the code as follows to handle the backspace key event:

    
      $(document).ready(function () {
                var spread = new GC.Spread.Sheets.Workbook(document.getElementById("spread"), {sheetCount:2});
                var activeSheet = spread.getActiveSheet();
    
                spread.commandManager().register('myCmd',
                    function ColorAction() {
                        //Click on a cell and press the Enter key.
                        activeSheet.getCell(activeSheet.getActiveRowIndex(), activeSheet.getActiveColumnIndex()).backColor("red");
                    }
                );
    
                //Map the created action to the Enter key.
                spread.commandManager().setShortcutKey('myCmd', GC.Spread.Commands.Key.backspace, false, false, false, false);
               
            });
    
    
    

    Thanks,

    Deepak Sharma

  • Posted 13 November 2017, 5:52 am EST

    Thanks Deepak, much appreciated.

Need extra support?

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

Learn More

Forum Channels