PDA

View Full Version : [FIXED][3.0] Menu extend bug



flylaputa
29 Apr 2009, 6:56 AM
Hi experts,

I know that Saki have posted a thread regarding the menu extend problem, but it seems to be slightly different to the behaviour I am getting, so I am going to post the code here. The problem is that the menu does get created, but the 'itemclick' event is not fired, and there is a 'this.parentMenu' is null error. Note that if the menu is not extended and created, it works perfectly.



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../../ext-3.0-rc1/resources/css/ext-all.css">
<script type="text/javascript" src="../../../ext-3.0-rc1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../../ext-3.0-rc1/ext-all-debug.js"></script>
<title id="page-title">Title</title>
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../../../ext-3.0-rc1/resources/images/default/s.gif';
MyMenu = Ext.extend(Ext.menu.Menu, {
initComponent:function() {
var config = {
items:[{
text:'Item 1'
},{
text:'Item 2'
},{
text:'Submenu'
,menu:{
listeners:{
itemclick:function() {
alert('hi');
}
}
,items:[{
text:'Subitem 1'
}]
}
}]
};
Ext.apply(this, Ext.apply(this.initialConfig, config));
MyMenu.superclass.initComponent.apply(this, arguments);
}
});
Ext.onReady(function() {
Ext.QuickTips.init();
var dummyData = [
['C11', 'C12', 'C13'],
['C21', 'C22', 'C23']
];
var aGrid = new Ext.grid.GridPanel({
viewConfig: {forceFit: true},
cm: new Ext.grid.ColumnModel([
{header: 'C1', width: 20, sortable: true, dataIndex: 'C1'},
{header: 'C2', width: 20, sortable: true, dataIndex: 'C2'},
{header: 'C3', width: 20, sortable: true, dataIndex: 'C3'}
]),
store: new Ext.data.Store({
data: dummyData,
reader: new Ext.data.ArrayReader({}, [
{name: 'C1'},
{name: 'C2'},
{name: 'C3'}
])
})
});
var bMenu = new Ext.menu.Menu({
items: [
{
text: 'B1'
}, {
text: 'B2',
menu: new Ext.menu.Menu({
items: [
{
text: 'B2.1'
}
]
})
}
],
listeners: {
itemclick: function() {
alert('itemclick');
}
}
});
var theMenu = new MyMenu({
});
aGrid.on('rowcontextmenu', function(grid, rowIndex, evt) {
evt.stopEvent();
theMenu.showAt(evt.getXY()); // this line doesn't work
//bMenu.showAt(evt.getXY()); // this line works
}, this);
var fullPanel = new Ext.Panel({
width: 1000,
height: 500,
title: 'full panel',
layout: 'fit',
renderTo: document.body,
items: [
aGrid
]
});
});
</script>
</head>
<body style="margin:40px">
</body>
</html>

evant
30 Apr 2009, 5:07 PM
Fixed in SVN. Note that in your extended class you haven't specified an xtype for the menu, which you'll need to do.

flylaputa
6 May 2009, 12:51 AM
Thanks so much, it's working now.