PDA

View Full Version : How to Add Mulitple Widgets?



haden
22 Apr 2011, 12:49 PM
I'd like to add a form and two grids to a window or container. I'd like to arrange them vertically and have a fixed amount of space (or margin) between them.

Is this something that gets specified in a layout (using an Items config) or in a container such as a Panel - or both? I see that AnchorLayout has an Items section but I don't know where to add identifiers for my components (eg. myForm, myGrid1, myGrid2).

Appreciate any help!

friend
25 Apr 2011, 10:46 AM
Here's a big/dumb/trivial layout which does (I think) what you want:



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="ext/resources/css/xtheme-blue.css" id="theme" />

<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"></script>


<script type="text/javascript">
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
Ext.QuickTips.init();

var form = new Ext.form.FormPanel({
height: 100,
margins: '5 0 5 0',
padding: 5,
items: [{
xtype: 'textfield',
fieldLabel: 'Last Name',
name: 'lastName'
},{
xtype: 'textfield',
fieldLabel: 'First Name',
name: 'firstName'
},{
xtype: 'textfield',
fieldLabel: 'Phone',
name: 'phone'
}]
});

var grid1 = new Ext.grid.GridPanel({
columns: [
{header: 'Last Name', dataIndex: 'lastName', width: 110},
{header: 'First Name', dataIndex: 'firstName', width: 110},
{header: 'Phone', dataIndex: 'phone', width: 110},
],
flex: 1,
margins: '5 0 5 0',
store: new Ext.data.JsonStore({
fields: ['lastName', 'firstName', 'phone'],
data: []
})
});

var grid2 = new Ext.grid.GridPanel({
columns: [
{header: 'Last Name', dataIndex: 'lastName', width: 110},
{header: 'First Name', dataIndex: 'firstName', width: 110},
{header: 'Phone', dataIndex: 'phone', width: 110},
],
flex: 1,
margins: '5 0 5 0',
store: new Ext.data.JsonStore({
fields: ['lastName', 'firstName', 'phone'],
data: []
})
});


var containerPanel = new Ext.Panel({
layout: 'vbox',
flex: 1,
height: 600,
padding: '5 5 5 5',
renderTo: 'contentDiv',
title: 'VBOX layout with Form and Two Grids',
width: 800,
items: [form, grid1, grid2]
});

});
</script>
</head>
<body>
<div id="contentDiv"></div>
</body>

</html>

haden
25 Apr 2011, 12:33 PM
Hey friend,

Terrific example! Thanks so much!

I found and have begun modifying one of the form examples (shows a grid of companies, displays details in a form) but your example holds two grids plus it uses containers within containers, thus showing me another way.

One question: I would have thought each grid needed to have their own config. Does it apply to all items by default?

var gridPanel = new Ext.Panel({
region: 'center',
layout: 'hbox',
padding: '5 5 5 5',
items: [gridLeft, {xtype: 'panel', border: false, width: 5},gridRight]
});