I'm having problems trying to understand formatting a vbox in Sencha Touch 2. My goal is to have each child to be full height (flex divides the screen in portions). To keep it simple, I have a detail view that shows one record data, then a list of items that correlate to that record.
Right now, using flex, each child is a set height and scroll themselves. I want them to be full height and the parent only scroll. If I take the flex out nothing shows up.
Ext.define('app.view.MainView', {
updateData : function(data) {
var panels = this.query('panel[tpl]'),
pLen = panels.length,
panel;
for ( p = 0; p < pLen; p++) {
panel = panels[p];
panel.setData(data);
}
this.callParent(arguments);
},
extend: 'Ext.Container',
xtype: 'mainView',
config: {
layout: {
type: 'vbox'
},
scrollable: true,
title: '',
items: [
{
xtype: 'panel',
flex: 1,
scrollable: true,
styleHtmlContent: true,
tpl: Ext.create('Ext.XTemplate',
'<div class="view-top" id="view-{id}">' +
'<div>{body}</div>' +
'</div>')
},
{
xtype: 'component',
cls: 'dark',
html: 'Top View'
},
{
flex: 1,
xtype: 'list',
store: 'ViewStore',
variableHeights: true,
itemTpl: [
'<div>{subject}</div>'
]
}
]
}
});
Found a solution, for those of you who may land here with the same issues I will post solution.
Basically I had to count the height of each list element after the view was painted and then set the height of the id for the list to that new height (NOTE: I had to add the itemcount + 5 to the total height to accommodate for each item)
Ext.define('app.view.ViewMain', {
updateData : function(data) {
var panels = this.query('panel[tpl]'),
pLen = panels.length,
panel;
for ( p = 0; p < pLen; p++) {
panel = panels[p];
panel.setData(data);
}
this.callParent(arguments);
},
extend: 'Ext.Container',
xtype: 'viewMain',
config: {
layout: {
type: 'vbox',
align: 'stretch'
},
scrollable: true,
title: '',
items: [
{
xtype: 'panel',
height: 'auto',
scrollable: null,
styleHtmlContent: true,
tpl: Ext.create('Ext.XTemplate',
'<div class="guest-top" id="view-{id}">' +
'<div>{body}</div>' +
'</div>')
},
{
xtype: 'component',
cls: 'dark',
html: 'Guest Panels'
},
{
xtype: 'list',
id: 'panelList',
store: 'ViewStore',
height: 1000,
scrollable: false,
variableHeights: true,
itemTpl: [
'<div>{subject}</div>'
]
}
],
listeners: {
painted: function(element, eOpts){
var totalHeight = 0;
var items = Ext.getCmp('panelList').getViewItems();
var itemsLn = items.length;
for (i = 0; i < itemsLn; i++) {
item = items[i];
totalHeight = totalHeight + item.element.dom.clientHeight;
}
Ext.get('panelList').setHeight(totalHeight + itemsLn + 5);
}
}
}});