PDA

View Full Version : How can I change the label's text ?



vicent
13 Jun 2007, 7:32 AM
I have add a text to the toolbar , how can I change the text of the label ?


var label = 'this is a label';
var dlg_tbar = new Ext.Toolbar('dlg_tbar');
dlg_tbar.add(label);
label.innerText = 'the new text';

I try to useing the red color code ,but it can not change the label's text , how can I do that?

jsakalos
13 Jun 2007, 8:25 AM
You can try something like this:




var ti = new Ext.Toolbar.TextItem("text");
ti.getEl().update("new text");



No warranty ;) I haven't tried personally.

jsakalos
13 Jun 2007, 8:27 AM
Or, event better:




var ti = tb.addText("text");
ti.getEl().update("new text");

vicent
13 Jun 2007, 5:11 PM
Or, event better:




var ti = tb.addText("text");
ti.getEl().update("new text");



the fireBug show the error message " ti.getEl().update is not a function "

jsakalos
13 Jun 2007, 9:52 PM
the fireBug show the error message " ti.getEl().update is not a function "

Oh yes, getEl returns HTML element. Try:




Ext.get(ti.getEl()).update('new text');

// or, if it is only one-shot change

Ext.fly(ti.getEl()).update('new text');

vicent
14 Jun 2007, 7:44 AM
Oh yes, getEl returns HTML element. Try:




Ext.get(ti.getEl()).update('new text');

// or, if it is only one-shot change

Ext.fly(ti.getEl()).update('new text');



Yes , It works good ,thanks a lot :)

Arpita2u.k
24 Mar 2009, 11:08 PM
Deleted. Please do not post the same question in multiple places.

linuxguy2001
11 Jul 2011, 11:53 AM
First grab the field id:


slabel = Ext.getCmp('iselector_id');

The apply the new text, you can use a value or just any text. Say you want to apply the value of another field to this label:


dv = rec.get('Service'); // I get this after clicking on my grid
// Now update the label
slabel.label.update(dv);

If you want to just update the label with any random text, just do this:


slabel.label.update('Some random text here');


You're welcome. Please visit www.foscode.com for more user friendly helpful tutorials on extjs.