开发者

Adding listener to an editor grid panel

开发者 https://www.devze.com 2023-03-19 05:27 出处:网络
There is an Editor grid panel. I am trying to add a listener to t开发者_运维知识库he cell click event.I have tried to do it in different ways:

There is an Editor grid panel.

I am trying to add a listener to t开发者_运维知识库he cell click event. I have tried to do it in different ways:

gridPanel.addListener('cellclick',myfunction);  

inside the grid:

listeners: {
    cellclick: myfunction
}

I have tried to do it in the selectionModel object.

None of them worked.

Where can be the problem?


If you can't add the listener as a config parameter, it's probably because you're having problems with the callback function not being in scope, similar to this:

> var obj = { greetMe: this.sayHi, sayHi: function(){ console.log('hi'); }};
undefined

> obj.greetMe();
TypeError: Property 'greetMe' of object #<Object> is not a function

> obj.greetMe
undefined

In the first line, this was still referring to the global (read: window) object at the time the object was defined. So this.sayHi === window.sayHi === undefined. The same thing happens when you define Ext config objects. Try defining the callback inline:

> var obj = { greetMe: function(){ console.log('hi'); }};
undefined

> obj.greetMe()
hi

Other options:

  1. Define the function in a wider scope, outside of your class
  2. Attach the listener within the constructor or within initComponent, by which time your class methods should be instantiated
  3. Attach the listener sometime later


You have to use cellmousedown of grid panel or cell selectionchange of selection model.


addListener worked. I had some syntax error. Still adding the listener as a parameter doesn't work


For row selection I put it on the selection model and for double clicks on the grid directly. This works well but I must warn you if you don't prevent the default event you will get horrible memory consumption.

Ext.onReady(function(){

requestGrid.getSelectionModel().on('rowselect', handleRowSelect);
requestGrid.on('rowdblclick', handleDoubleClick);

}

It would help if I read :) My solution is for row selection not cell selection but it might very well work.

0

精彩评论

暂无评论...
验证码 换一张
取 消