SpreadJS 15
GC.Spread.Commands Namespace / CommandManager class / register Method
The name of the command.
The object that defines the command.
The key code.
true if the command uses the Ctrl key; otherwise, false.
true if the command uses the Shift key; otherwise, false.
true if the command uses the Alt key; otherwise, false.
true if the command uses the Command key on the Macintosh or the Windows key on Microsoft Windows; otherwise, false.
In This Topic
    register Method
    In This Topic
    Registers a command with the command manager.
    Syntax
    var instance = new GC.Spread.Commands.CommandManager(context);
    var value; // Type: any
    value = instance.register(name, command, key, ctrl, shift, alt, meta);
    function register( 
       name : string,
       command : Object,
       key : undefined,
       ctrl : boolean,
       shift : boolean,
       alt : boolean,
       meta : boolean
    ) : any;

    Parameters

    name
    The name of the command.
    command
    The object that defines the command.
    key
    The key code.
    ctrl
    true if the command uses the Ctrl key; otherwise, false.
    shift
    true if the command uses the Shift key; otherwise, false.
    alt
    true if the command uses the Alt key; otherwise, false.
    meta
    true if the command uses the Command key on the Macintosh or the Windows key on Microsoft Windows; otherwise, false.
    Example
    //For example, the following code registers the changeBackColor command and then executes the command.
    var command = {
      canUndo: true,
      execute: function (context, options, isUndo) {
        var Commands = GC.Spread.Sheets.Commands;
        options.cmd = "changeBackColor";
        if (isUndo) {
          Commands.undoTransaction(context, options);
          return true;
        } else {
          Commands.startTransaction(context, options);
          var sheet = context.getSheetFromName(options.sheetName);
          var cell = sheet.getCell(options.row, options.col);
          cell.backColor(options.backColor);
          Commands.endTransaction(context, options);
          return true;
        }
      }
    };
    var spread = GC.Spread.Sheets.findControl(document.getElementById("ss"));
    var commandManager = spread.commandManager();
    commandManager.register("changeBackColor", command);
    commandManager.execute({cmd: "changeBackColor", sheetName: spread.getSheet(0).name(), row: 1, col: 2, backColor: "red"});
    Remarks
    The command name should be set when defining the command function, if the user needs to use the Undo action with the registered custom command.
    See Also