Mends.One

¨How set the title to the panel dynamically by getting the panel using its id in inExt.getCmp('myPanelID'), What are the properties to set title

Sencha Touch 2, Sencha Touch, Extjs

I have a Ext panel and I want to set the Title of the panel from some variable .

I have the id of the panel and I need to set the title of the panel from it.

I am looking for some thing like this,

Ext.getCmp('myPanel').setTitle(); like atribute

Ext.define('Myapplication.view.Contacts', {
    extend: 'Ext.Panel',
    alias: 'widget.Contacts',
    id: 'myPanelID',
    ----
    -----
    ------
    -----

    listeners: [
        {
           fn: 'initComponent',
           event: 'initialize'
        }
    ]
},
initComponent: function(component, options, wstitle) {
    Ext.getCmp('myPanelID').header.title = ('Title of panel'); //Not working
    Ext.getCmp('myPanelID').setTitle= ('Title of panel'); //Not working
}

alway got an error:

TypeError: 'undefined' is not an object (evaluating 'Ext.getCmp('myPanel').setTitle')

0
U
user1425472
Jump to: Answer 1 Answer 2 Answer 3

Answers (3)

Ext.Panel is a instead of Ext.Container so, is a container and not is an object. If you want change someone like title you can try something like this,

Ext.define('Myapplication.view.Contacts', {
    extend: 'Ext.Panel',
    alias: 'widget.Contacts',
    id: 'myPanelID',
    ...

    html: '<div>Your Title</div>',
    ...

    initComponent: function(component, options, wstitle) {
        Ext.getCmp('myPanelID').setHtml('<div>Another Title</div>');
    }
})

Hope these helps. :)

1
H
hekomobile

Ext.getCmp('myPanelID').setTitle is a function.

So...

Ext.getCmp('myPanelID').setTitle('Title of panel');

Is what you are looking for

0
A
Alex

Comments:

user1425472 said:
in this case also got an error TypeError: 'undefined' is not an object (evaluating 'Ext.getCmp('myPanel').setTitle')

you got a syntax error. You write

Ext.getCmp('myPanelID').setTitle= ('Title of panel'); //Not working

remove the = char

Ext.getCmp('myPanelID').setTitle('Title of panel'); //Works like a charm

cheers, Oleg

0
O
olegtaranenko

Related Questions