Search code examples
extjsextjs2

How to get grid in onContextMenu function


I have following code

grid.on('contextmenu', this.onContextMenu, this);

onContextMenu: function (e) {
      // I want the grid here
    },

there is only one argument 'e'. I cannot use 'this' as the grid is inside panel and 'this' returns panel not the grid. I am using Extjs 2.3.0.


Solution

  • You can pass the grid to your handler yourself:

    grid.on('contextmenu', function(e) {
        this.onContextMenu(e, grid);
    }, this);
    

    Your handler method:

    onContextMenu: function(e, grid) {
        // have fun with your grid
    }