PDA

View Full Version : Adding & Removing Select Event Listener From Grid



azinyama
23 Oct 2012, 9:29 PM
Good day all!!!

I have a girdpanel to which I'm a select listener function to from my controller. See code below:



init: function()
{
this.control(
{
'registrationWindow gridpanel[name=Member]':
{
select: this.onMemberSelect
},
});
},

onMemberSelect: function(grid, record, index, eOpts)
{
console.log('firing member select');
},



Now what I'm trying to do is add a new row


remove the select listener

select the row (should not fire select event because it has been remove)

add the select listener



This is my code, see below:



onAddMember: function(button, e)
{
this.getMemberStore().removeAll(false);
this.getMemberStore().suspendAutoSync();
this.getMemberStore().insert(0, this.getMemberModel().create());
this.getMemberStore().resumeAutoSync();

this.getMemberSearchGrid().getSelectionModel().un('select', this.onMemberSelect, this); //select listener is not being remove and console still outputs 'firing member select'
this.getMemberSearchGrid().getSelectionModel().select(0);
this.getMemberSearchGrid().getSelectionModel().on('select', this.onMemberSelect, this);

this.showMemberEditWindow(this.getMemberSearchGrid().getSelectionModel().getSelection()[0]);
},


Any help is greatly appreciated

James Goddard
24 Oct 2012, 5:36 AM
You could just call suspendEvents/resumeEvents.

azinyama
24 Oct 2012, 1:53 PM
Thanx...

That worked great:



this.getMemberDependantGrid().getSelectionModel().suspendEvents(false);
this.getMemberDependantGrid().getSelectionModel().select(0);
this.getMemberDependantGrid().getSelectionModel().resumeEvents(false);



Just out of curiosity; how would I be able to acheive the same thing using removeListener and addListener.

James Goddard
24 Oct 2012, 3:19 PM
The code you have looked ok. I know that un is REALLY picky about getting the exact same params as the on. It may be that the control does something different like wrapping the callback so that it doesn't match the function you are passing in. I'd have to check the code to be sure.