PDA

View Full Version : newbie question : try to destroy a contextMenu



flamant
12 Feb 2011, 8:45 AM
Hi,
I try to destroy the contextMenu from the click handler but when I log the menu it is still there



this.ctxMenu = new Ext.menu.Menu({
items: [{ }, { },
{ id: 'getAuditTrailCtxMenu_'+fieldId,
text: '<spring:message code="application.auditTrail"/>',
iconCls: 'auditTrail',
fieldId: fieldId,
subjectId: subjectId,
screenSequence: screenSequence,
rowSeq: rowSeq,
listeners: {
click: function(item, evt) {
var field = Ext.getCmp(item.fieldId);
getAuditTrail(field, item.subjectId, item.screenSequence, item.rowSeq);
var menu = item.parentMenu;
console.log('parentMenu=');
console.log(menu);
menu.destroy();
console.log(menu);
}
}

}
Why I am trying to do this is because when I removeAll the components from the grand Parent panel, the contextMenus (put on Ext.Element) are not removed

Thank you in advance for your answers

valititi
13 Feb 2011, 3:18 AM
try to let Ext to give you an id for your contextMenu. I had a similat problem, and using automatic id (just in this case) work for me...
hope this can help you

flamant
13 Feb 2011, 10:15 AM
Hi valititi and thank you for your answer,
Actually I already let Ext give me an id for my contextMenu.

I found a solution : I had to implement a custom destroy function that work in my case:



elt.on('contextmenu', function(evt, elRef) {
evt.stopEvent();
this.ctxMenu = new Ext.menu.Menu({
items: [ {...},{...},{...}]
,
listeners: {
hide: function(menu) {
customDestroy(menu);
}
}});
this.ctxMenu.showAt([evt.getPageX(), evt.getPageY()]);
});

function customDestroy(menu){
if(!menu.isDestroyed){
if(menu.fireEvent('beforedestroy', this) !== false){
menu.destroying = true;
menu.beforeDestroy();
menu.remove();
if(menu.rendered){
var parentDomElement = menu.getEl().dom.parentNode;
parentDomElement.removeChild(menu.getEl().dom);
}
// Stop any buffered tasks
if(menu.focusTask && menu.focusTask.cancel){
menu.focusTask.cancel();
}
menu.onDestroy();
Ext.ComponentMgr.unregister(menu);
menu.fireEvent('destroy', menu);
menu.purgeListeners();
menu.destroying = false;
menu.isDestroyed = true;
}
}
}


I had to manually remove the DOM underlying element from the page

Thank you again for replying me