-
3 Nov 2012 9:14 AM #1
Empty panel header title is always rendered
Empty panel header title is always rendered
REQUIRED INFORMATIONExt version tested:
- Ext 4.1.1
- Ext 4.1.1 rev a
- Safari 6.0.1
- Chrome 22.0.1229.94
- HTML5
- I want to add some centered text after the title in a panel header.
- Panel headers that use an items config always render the items before the title. Thus I need to put the title in the items config and omit the header's title config.
- Ext is always rendering an empty header text element which throws off the layout.
- This entire scenario makes it next to impossible to customize a panel header without copying private framework code.
- Create a panel. Omit the title config.
- Give it a header config. Omit the title config here as well.
- In the header config, add a container to the items collection that represents the manually managed title.
- Add another container to the items collection. Add css to center the text. Give it a flex of 1.
- The container with the centered text is rendered in the center of the header.
- The container with the centered text is rendered offset from the center due to the presence of an empty header text element.
PHP Code:Ext.create('Ext.Panel', {
title: 'Example',
width: 300,
height: 400,
renderTo: Ext.getBody(),
layout: 'border',
defaults: {
height: 100,
width: 300
},
items: [
{
xtype: 'panel',
region: 'center',
//title: 'panel 1',
html: 'panel 1',
collapsible: true,
header: {
defaults: {
border: 1,
style: {
borderColor: 'red',
borderStyle: 'solid'
}
},
items: [
{
xtype: 'container',
html: 'title',
cls: 'x-panel-header-text-container'},
{
xtype: 'container',
html: '<p style="text-align:center">centered text</p>',
flex: 1}
]
}}
]
});
HELPFUL INFORMATION
See this URL for live test case:
http://jsfiddle.net/k2puA/2/
Debugging already done:- If the title config is not specified, the Header class sets it to a non-breaking space.
- This non-breaking space is then rendered with a flex of 1, after the items collection.
- Specifying various css classes on the manually managed title in the items collection seems to have no effect. The header class always wants to include the non-breaking space and then render it.
- not provided
- only default ext-all.css
- OS X 10.8.2
- Windows 7 Pro SP1
Last edited by mpost; 3 Nov 2012 at 10:08 AM. Reason: fix code formatting
-
3 Nov 2012 3:12 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Why not use titleAlign to center some text?
Code:Ext.create('Ext.panel.Panel', { title : 'Example', width : 300, height : 400, renderTo : Ext.getBody(), layout : 'border', defaults : { height : 100, width : 300 }, items : [ { xtype : 'panel', region : 'center', title : 'panel 1', titleAlign : 'center', html : 'panel 1', collapsible : true, header : { defaults : { border : 1, style : { borderColor : 'red', borderStyle : 'solid' } }, items : [ { xtype : 'container', html : 'title', cls : 'x-panel-header-text-container' } ] }} ] });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Nov 2012 7:02 PM #3
Two reasons:
- For the case where I want to center some text, I want the title to be left justified. You example is the opposite: title is centered, other text is left justified.
- This bug also affects cases where you want to right justify text. For example, if I want a left justified title, but want to add a right justified text. The text would need to be specified in the items config, but then it would be rendered before the title. Thus the title also has to be specified in the items config, but then the empty title automatically kicks in. This makes the right justified text appear to be centered. Example: http://jsfiddle.net/KQTfP/2/
-
4 Nov 2012 9:02 PM #4
The panel header is a fairly unique component, similar the paging toolbar. It can accept items, but by default they are mostly configured externally by another component. As such, it makes it difficult to provide a reasonable level of flexibility without adding significant complication.
As such, your best bet is to override initComponent and manipulate the items collection:
Code:Ext.define('MyHeader', { extend: 'Ext.panel.Header', initComponent: function(){ this.callParent(arguments); this.remove(this.titleCmp); delete this.titleCmp; // have at it! } });Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote