PDA

View Full Version : ExtJS Context Menu id



purlogic
31 Mar 2011, 3:56 PM
Just fixed a strange issue, wanted to bring it up and get feedback as to why this occurs.

I created a context menu for a grid, and gave the context menu an id. The Items in the context menu are created dynamically depending on the values in the grid.



var ctx = new Ext.menu.Menu({});
ctx.addItem(new Ext.menu.Item({text : 'Edit Client', iconCls : 'edit-client', handler: Admin.editClient}));
if(grid.getSelectionModel().getSelected().data.active == 0) {
ctx.addItem(new Ext.menu.Item({text : 'Activate Client', iconCls : 'activate-client', handler: Admin.activateClient}));
} else if(grid.getSelectionModel().getSelected().data.active == 1) {
ctx.addItem(new Ext.menu.Item({text : 'Deactivate Client', iconCls : 'deactivate-client', handler: Admin.deactivateClient}));
}
ctx.addItem(new Ext.menu.Item({text : 'E-Mail Client', iconCls : 'email-client', handler: Admin.emailClient}));
ctx.addItem('-');
ctx.addItem(new Ext.menu.Item({text : 'Add Widget', iconCls : 'add-widget', handler: Admin.addWidget}));
ctx.addItem(new Ext.menu.Item({text : 'View Widgets', iconCls : 'view-widgets', handler: Admin.viewWidgets}));
ctx.addItem('-');
ctx.addItem(new Ext.menu.Item({text : 'Export Grid', iconCls : 'export-grid', handler: Admin.exportGrid}));
ctx.showAt(e.xy);


I specify an id for the context menu (ie - id : 'ctx-menu-id'), when the context menu is created and displayed on the screen, it repeats the content of the context menu several times. So instead of having a context menu of 6 Items, it shows up as either 12 or 18 or 6 (appears to occur randomly). When I delete the id attribute, this fixes the problem. The attachment shows the Items repeating twice (12 Items when there should only be 6). Again, removing the "id" attribute appears to solve the issue.