English 中文(简体)
How to add row double click event listener when extending grid panel with Ext.define()?
原标题:

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

最佳回答

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();
        }
    },




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签