extjs add items to a formpanel in a row dynamically

5.1k Views Asked by At

Using ExtJS 3.4 - I have a formpanel which lays out three buttons in a row. I believe the right way to do this is to nest item blocks, code shows what I am doing.

var myPanel = new Ext.form.FormPanel({
    id:'myPanel',
    height:300,
    width: 800,
    items:[{
        layout : 'column' ,border:false,buttonAlign : 'left', bodyStyle : 'padding:15px 20px 0',
        items:[{
                      layout:'column' , border:false,  
                      items:[saveSelectedButton, deleteSelectedButton, cancelButton ]
               }]
      }]


});

What I really need to do is add the buttons dynamically so the items block is empty at first items:[] and then I call

myPanel.add(saveSelectedButton, deleteSelectedButton, cancelButton);

but the buttons are rendered in a column, any suggestions?

1

There are 1 best solutions below

0
On

Usage of buttons instead of items is more preferred way.

var myPanel = new Ext.form.FormPanel({
// ... 
    buttons:[saveSelectedButton, deleteSelectedButton, cancelButton]  
});

For adding them dynamically you should use addButton method. E.g.

var form = new Ext.form.FormPanel({
        title: 'Test',
        el: 'test',
        url: '',
        method: '',
        items: [{}],
        buttons: [{}]
    });
    form.addButton({
        text: 'Test Button',
        id: 'test-button',
        type: 'submit'
    });
    form.render();