PDA

View Full Version : Changing the Panel Header Title on an Event



cahello
4 Dec 2012, 7:50 AM
Hi,

I have a panel which is updated on another grid's row double click. Everything changes except for the title of the panel. Here is the code:


listeners : {
itemdblclick: function(dv, record, item, index, e) {
Ext.getCmp('panel1').setTitle('Title changed'); //this does not work
}
}





The error: 'Cannot call method 'setTitle' of undefined'.

What am I missing here?

'panel1' is defined in another .js file where I have also defined 'panel1' as a global variable in the .js file. The code is:


var panel1= Ext.create('Ext.panel.Panel',{
autoshow : true,
id: 'panel1',
name: 'panel1',
renderTo : 'panelview',
layout : 'border',
height: 400,
title: 'CANT CHANGE THE TITLE',
items : [{
xtype: 'panel',
align: 'stretch',
region:'center',
........
}]
});

Alexander Bauer
4 Dec 2012, 9:04 AM
For some reason the component manager cant find the component with id 'panel1'. If you do such queries always wrap it with a if(), it may fail updating the tile but at least the app will continue to work.

You have defined the renderTo property, it may overrides the origin id and becomes panelview.

cahello
4 Dec 2012, 10:45 AM
But how do I integrate the code to update the title of my panel header on dblclick event?

Alexander Bauer
4 Dec 2012, 10:47 AM
try it with Ext.getCmp('panelview') instead.

Keep in mind: working with ids is a bad approach, it will getting fuzzy when the project grows. You may want to re-think your layout logic and check out the component query in the docs.

cahello
4 Dec 2012, 10:56 AM
The error does not come anymore but the title does not change either. I have used : Ext.getCmp('panelview').setTitle('Title changed'); instead of Ext.getCmp('panel1').setTitle('Title changed');

I dblclick on one of the grid rows of the other grid panel but the title of this panel does not change.

Alexander Bauer
4 Dec 2012, 10:59 AM
please try:

console.log(Ext.getCmp('panelview'));
console.log(Ext.getCmp('panel1'));
and check if you get the right panel component.
If not, it must be some other issue.

cahello
4 Dec 2012, 11:20 AM
I checked that and I am getting some dom null error.

cahello
4 Dec 2012, 11:36 AM
I got this working. It seems that I was allocating the wrong global variable. Thanks for the help. :)