PDA

View Full Version : how to remove button window dynamicaly



iss
25 Feb 2011, 3:57 AM
Hi ,

I need to add/remove buttons to a window at run time. Adding is working fine but removing the button is not working. the button actualy is removed(it is deleted from window.buttons array) but I couldnt make the window to repaint itself not to show removed buttons

here is the code
function hasButton(user) {

for (b in bbWin.buttons) {
if (user.id === b)
return true;
}
return false;
}
var bbWin = new Ext.Window({
x : 20,
y : ch - 200,
height : 10,
width : cw - 100,
minimizable : true,
closeAction : 'close',
items : [],

buttons : [{
text : 'some title',
height : 30,
width : 100

}],
buttonAlign : 'left',
addEle : function(user, win) {

if (!hasButton(user)) {
bbWin.addButton({
id : 'but_' + user.id,
text : user.name,
height : 30,
width : 100,
xtype : 'button',
handler : function() {
win.show();
}
});

}
bbWin.doLayout();
},
removeEle:function (user){

var c=Ext.getCmp("but_"+user.id)
bbWin.buttons.remove(c);
bbWin.doLayout()


},
showWin : function(id) {

}
});

laurentParis
25 Feb 2011, 8:46 AM
I suggest



var bbWin = new Ext.Window({
height: 200,
width: 300,
renderTo: Ext.getBody(),
items: [],
buttons: [{
text: 'some title',
height: 30,
id: 'test',
width: 100,
handler: function () {
var button = Ext.getCmp('test');
button.destroy();
}
}],
buttonAlign: 'left'
});
bbWin.show();