How do i choose different activeCell in setSelection?

Posted by: razeris563 on 26 August 2021, 3:54 am EST

    • Post Options:
    • Link

    Posted 26 August 2021, 3:54 am EST

    Hi guys, I have a shortkey that selects the whole row (depending on which cell is clicked at the moment) where i use setSelection method. When I use it, the whole row gets selected but there are 2 problems:

    a) It selects the first cell in the row as the activeCell, just as it’s state in the documentation but when i tried to use setActiveCell aswell, it didn’t work.

    b) The cell isn’t really active since i can’t write anything in it after this row selection.

    Thanks for the help!

  • Posted 27 August 2021, 1:52 am EST

    Hi,

    Please refer to the following code snippet that achieves the same and let us know if you face any issues.

    
      var command = {
        canUndo: true,
        execute: function (spread, options, isUndo) {
          var Commands = GC.Spread.Sheets.Commands;
          if (isUndo) {
            Commands.undoTransaction(spread, options);
            return true;
          } else {
            options.cmd = "selectRow";
    
            Commands.startTransaction(spread, options);
            let sheet = spread.getActiveSheet();
            let colCount = sheet.getColumnCount();
            let activeRow = sheet.getActiveRowIndex();
            let activeCol = sheet.getActiveColumnIndex();
            sheet.clearSelection();
            sheet.setSelection(activeRow, activeCol, 1, colCount);
            sheet.getSelections()[0].col = 0;
            sheet.repaint();
            Commands.endTransaction(spread, options);
    
            return true;
          }
        }
      };
    
      var commandManager = spread.commandManager();
      /*75 is the code of k*/
      commandManager.register("selectRow", command, 75, true, false, false);
    
    

    sample: https://codesandbox.io/s/spread-js-starter-forked-w59mk?file=/src/index.js

    Regards

    Avinash

Need extra support?

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

Learn More

Forum Channels