How to add row double click event listener when extending grid panel with Ext.define()?

Petrunov picture Petrunov · Apr 22, 2011 · Viewed 45.8k times · Source

I am extending GridPanel with Ext.define() (Ext v4).

I need to get the row data when a grid row is double clicked. At this point I cannot even get the event listener working:

Ext.define('Application.usersGrid', {
extend: 'Ext.grid.GridPanel',
alias: 'widget.usersgrid',


viewConfig: {
    listeners: {
        dblclick: function(dataview, index, item, e) {
            alert('dblclick');
        }
    }
},
...

What is wrong here?

If anyone needs the answer- this is the right way:

Ext.define('Application.usersGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.usersgrid',


viewConfig: {
    listeners: {
        itemdblclick: function(dataview, record, item, index, e) {
            alert('itemdblclick');
        }
    }
},
...

http://dev.sencha.com/new/ext-js/4-0/api/Ext.grid.GridView#event-itemdblclick

Answer

Abdel Raoof picture Abdel Raoof · Apr 22, 2011

You don't need to put the listener in the viewconfig. Here is my working configuration:

listeners : {
    itemdblclick: function(dv, record, item, index, e) {
        alert('working');
    }
},

Another thing is, you seems to have used Ext.grid.GridPanel in the extend property. But in documentation it's Ext.grid.Panel. But even with gridpanel, everything seems to work fine.

I would suggest to use the Ext JS 4 terms as it might cause to application breakage later in other 4.x versions.

Now, if you are using the new MVC architecture, you will want to move these actions to the controller rather than the view. You can refer to the MVC Architecture guide for details.