PDA

View Full Version : Grid removeListener



saravanakmr
1 Jul 2012, 10:24 PM
I configured grid with itemcontextmenu.I want to remove itemcontextmenu event from listeners.

can anyone give suggestion with small code?


Thanks

sword-it
2 Jul 2012, 12:33 AM
Hi saravanakmr,
Try the code give below:




Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: { 'items': [
{ 'name': 'Lisa', "email": "lisa@simpsons.com", "phone": "555-111-1224" },
{ 'name': 'Bart', "email": "bart@simpsons.com", "phone": "555-222-1234" },
{ 'name': 'Homer', "email": "home@simpsons.com", "phone": "555-222-1244" },
{ 'name': 'Marge', "email": "marge@simpsons.com", "phone": "555-222-1254" }
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
id:'simpsonsgrid',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Phone', dataIndex: 'phone' }
]
, afterRender: function () {
this.superclass.afterRender.apply(this,arguments);
this.addListener('itemcontextmenu',this.onitemcontextmenu,this);
}
, onitemcontextmenu: function () {
alert('right clicked');
},
height: 200,
width: 400,
renderTo: Ext.getBody()
});
Ext.create('Ext.button.Button', {
text: 'Remove Listener'
, scope: this
, renderTo: Ext.getBody()
, handler: function () {
var grid = Ext.getCmp('simpsonsgrid');
grid.removeListener('itemcontextmenu', grid.onitemcontextmenu, grid);
}
});



Firstly try to right click on grid, item contextmenu will work,I just add a button named "Remove Listener" , when you click on this button , itemcontextmenu listener will be removed from grid.