How to select row in grid on right-click ?

January 6th, 2009
  • Hi all !

    I have implemented an eventlistener for right-click in my grid. This displays a contextmenu. Works fine.

    But, I would also like to be able to select the row on which I right-clicked.

    Does anyone have any information/tips/solution to this ?

    Thanks !

    regards,
    Petter Kjeilen


  • @NOSLOW

    Thanks ! That did the trick :-)

    Petter


  • I recently had to do the same thing. My right-click context menu code was borrowed from the feed-view example in the examples folder (ext-2.1examplesfeed-viewerFeedGrid.js)

    Inside the onContextClick, I added this line near the end:

    this.getSelectionModel().selectRow(index); // select row that was right-clicked on


    Here's the full routine:

    onContextClick : function(grid, index, e){
    if(!this.menu){ // create context menu on first right click
    this.menu = new Ext.menu.Menu({
    id:'grid-ctx',
    items: [{
    text: 'View in new tab',
    iconCls: 'new-tab',
    scope:this,
    handler: function(){
    this.viewer.openTab(this.ctxRecord);
    }
    },{
    iconCls: 'new-win',
    text: 'Go to Post',
    scope:this,
    handler: function(){
    window.open(this.ctxRecord.data.link);
    }
    },'-',{
    iconCls: 'refresh-icon',
    text:'Refresh',
    scope:this,
    handler: function(){
    this.ctxRow = null;
    this.store.reload();
    }
    }]
    });
    this.menu.on('hide', this.onContextHide, this);
    }
    e.stopEvent();
    if(this.ctxRow){
    Ext.fly(this.ctxRow).removeClass('x-node-ctx');
    this.ctxRow = null;
    }
    this.ctxRow = this.view.getRow(index);
    this.ctxRecord = this.store.getAt(index);
    this.getSelectionModel().selectRow(index); // select row that was right-clicked on
    Ext.fly(this.ctxRow).addClass('x-node-ctx');
    this.menu.showAt(e.getXY());
    },


    HTH







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about How to select row in grid on right-click ? , Please add it free.