PDA

View Full Version : Trouble registering events in Grid constructor



JakeL
13 Aug 2012, 1:49 PM
Hi All.

Something I can't figure out. If I specify an event listener in a grid, like so:



listeners:
{
afterrender: function (sheet)
{
sheet.getSelectionModel().on("select", sheet.selectHandler, sheet);
}
},


everything is fine. however, what I thought was the same thing:



constructor: function (config)
{
this.callParent(arguments); //call base constructor
this.mon("afterrender", function (sheet)
{
sheet.getSelectionModel().on("select", sheet.selectHandler, sheet);
});
}

never triggers.

What am I doing wrong?

kaiden.vo
13 Aug 2012, 3:02 PM
2 issues with your code.

First - events are initialized in initComponent() - not in constructor. So, your code registers for the event when it is not setup.

Second - You're calling mon() , not on().

Cheers,

JakeL
13 Aug 2012, 3:22 PM
Thank you. Didn't think of trying in initComponent(). I've got it working for me now.

Can you shed some light on why mon() does not work? I had thought that just set up the event so it'd be removed when the component was destroyed, in this case, when a window is closed and the grid goes away.

Thank you,

-Jake

evant
13 Aug 2012, 3:32 PM
The event signatures for on/mon are different:



this.mon(someOtherObservable, 'foo', this.onFoo, this);


By binding it with mon(), we ensure that when we get destroyed, the listener that was bound to the ~other~ observable gets cleaned up. When a component is destroyed, any listeners it has are always removed, mon or not.

JakeL
13 Aug 2012, 3:37 PM
bingo, got it. That'll help me later for sure.

Thanks guys,

-Jake