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

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


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.


With the MVC approach in ExtJS 4 there's another smart way too to define such handlers. Some example code:

Ext.define('App.controller.Documents', {  extend: 'Ext.app.Controller',  stores: ['Documents'],  models: ['Document'],  views: [    'document.List',    'document.Edit',    'document.Preview'  ],    init: function() {    this.control({      /*         * a cool way to select stuff in ExtJS 4       */      'documentlist': {        itemdblclick: this.editDocument      },        /*         * simple access to components       */      'documentedit button[action=save]': {        click: this.updateDocument      },      });   },    editDocument: function(grid, record) {    var view = Ext.widget('documentedit');    view.down('form').loadRecord(record);  },    updateDocument: function(button) {    var win = button.up('window'),  // new selection API        form   = win.down('form'),  // in ExtJS 4        record = form.getRecord(),        values = form.getValues();    record.set(values);    win.close();  }});


listeners: {        select: 'xxxx',        itemdblclick: function (dv, record, item, index, e) {            var myBtn = Ext.getCmp('btnEdit');            myBtn.onClick();        }    },