PDA

View Full Version : Toolbar.replaceItems



joeri
12 Mar 2009, 12:40 PM
The following override adds a method to replace toolbar items after rendering. The argument is the same format as passed to the tbar config.


Ext.override(Ext.Toolbar, {
replaceItems: function(buttons) {
for (var i = this.items.getCount() - 1; i >= 0; i--) {
Ext.destroy(this.items[i]);
this.tr.removeChild(this.tr.childNodes[i]);
};
this.items.clear();
this.add.apply(this, buttons);
}
});

To use:


var toolbar = Ext.getCmp('toolbar');
toolbar.replaceItems([{
xtype: 'tbbutton',
text: 'Button 1'
},{
xtype: 'tbbutton',
text: 'Button 2'
}]);