Can't find what you're looking for?

Contact us or post in our forums and we'll help you find an answer.

Intercept right-click event in Angular

Background:

We are able to intercept a right-click event by adding an event listener to the Spread instance for the Context Menu.

Steps to Complete:

1. Get host element of current workbook

2. Add an event listener for the Context Menu

Getting Started:

Step 1: Get host element of current workbook

Get the host element using SpreadJS’s getHost() method:

 workbookInit(args){
      var spreadNS = GC.Spread.Sheets;
      const self = this;
      this.spread = args.spread;
    
    // Get the active sheet
      this.sheet = self.spread.getActiveSheet();
   // Get host element of SpreadJS
      this.spread.getHost();
}

Step 2: Add an event listener for Context Menu

Add an event listener to SpreadJS’s Context Menu, this is because the context menu is triggered when a user right-click.

 workbookInit(args){
      var spreadNS = GC.Spread.Sheets;
      const self = this;
      this.spread = args.spread;
    
    // Get the active sheet
      this.sheet = self.spread.getActiveSheet();
    // Get host elemement of SpreadJS
    // Add event listener to context menu
      this.spread.getHost().addEventListener("contextmenu", function (e) {
        // your code;
        console.log("right-clicked");
        e.preventDefault();
        return false;
      });
 }