extjs 4 - how to add button into panel header? - extjs

I have:
new Ext.Panel({
title: 'Header',
hideCollapseTool: true,
collapsible: true,
collapsed: true,
renderTo: 'mywrap',
width: '100%',
height: 'auto',
...
}
How can I replace header one button the entire width/height with hover and ▲ Header ▼ instead of title?
as_is-as_to_be

If I correctly understand what you want to achieve you can do something like this:
Ext.create('Ext.panel.Panel', {
border: true,
bodyStyle: {
padding: '10px'
},
collapsible: true,
hideCollapseTool: true,
html: 'Some data',
renderTo: Ext.getBody(),
title: '▲ Header ▼',
titleAlign: 'center',
titleCollapse: true
});
Check this working fiddle.
If you still want to add button with height / width 100% you can do something like this:
var myPanel = Ext.create('Ext.panel.Panel', {
...
title: '<button id="myButton" style="...">My header button</button>'
...
});
(do not forget to remove panel header padding)
and add handler to it via ExtJS, like this
// Get Ext.dom.Element via Ext.dom.Element.get() method
Ext.get('myButton').on('click', function() {
if(myPanel.getCollapsed())
myPanel.expand();
else
myPanel.collapse();
});
or JS, like this
document.getElementById('myButton').addEventListener('click', function() {
if(myPanel.getCollapsed())
myPanel.expand();
else
myPanel.collapse();
});
Check this working fiddle.
If you want to add some buttons to your header you can also use Ext.panel.Panel.tools config.
And ofcourse you can always overrite Ext.panel.Header.

Related

How to scroll container in EXT JS but only to specific component?

How to allow scrolling in extjs but only to some other component. For example, in the code below, the html component shouldn't go away from the screen.
Ext.create('Ext.Container', {
renderTo: Ext.getBody(),
scrollable: true,
items:[
{
xtype: 'datefield',
label: 'From',
},
{
xtype: 'datefield',
label: 'To',
},
{
padding: 50,
html: 'This should stick to the top',
height: 550,
},
{
xtype: 'grid',
height: 600,
scrollable: true
}
]
});
There is a few issues with your code. First, the container you add to the body is set to scrollable, set it to false if you don't want it scrolling.
Then you add it to the body element, even if it is not scrollable, its height will be the sum of its children, if that is taller than your body element, scrollbar will appear. But it is important to notice in this case what is scrolling is the body, not the component.
Then you said you want it to stick that html component on top, but what do you exactly mean by that? Make it appear above the two inputs? If you want that, add docked: 'top' to it.
Adding your container into a viewport instead of directly to body is a better approach, you can test this in sencha fiddle:
Ext.application({
name: 'Fiddle',
launch: function () {
const container = Ext.create('Ext.Container', {
scrollable: true,
items: [{
xtype: 'datefield',
label: 'From',
}, {
xtype: 'datefield',
label: 'To',
}, {
padding: 50,
html: 'This should stick to the top',
height: 550,
}, {
xtype: 'grid',
height: 600,
scrollable: true,
data: Array.from(Array(100).keys()).map(value=>({value})),
columns: [{text: 'value',dataIndex: 'value'}]
}]
});
Ext.Viewport.add(container);
}
});
Anyways, I don't really understand what are you trying to achieve, because if you set the outer component non-scrollable and put it into a component smaller than ~500px, how do you expect to see your grid? I suggest to take a

Not able to view fieldLabel of my hbox layout panel

I have a panel and the layout is hbox,I have two textfileds as items of the panel.
I am not able to view the fieldLabels when i execute .Please find the code
Ext.onReady(function(){
var panel = new Ext.Panel({
title:"HBox Panel",
layout:'hbox',
width:300,
height:200,
renderTo:document.body,
items:[
{
xtype:"textfield",
fieldLabel:"Label1"
},
{
xtype:"textfield",
fieldLabel:"Label2"
}
]
});
});
Note:I am working on Ext 3.2.1
Your layout should be form. From the api documentation:
fieldLabel config is only used when this Component is rendered by a
Container which has been configured to use the FormLayout layout
manager (e.g. Ext.form.FormPanel or specifying layout:'form').
As already said, the fieldLabel option will only apply in a form layout context (usually provided by the form panel).
As a quick fix, you can display your labels in BoxComponent:
Ext.onReady(function() {
var panel = new Ext.FormPanel({
title: "HBox Panel",
layout: 'hbox',
width: 300,
height: 200,
renderTo: document.body,
items: [{
xtype: 'box'
,html: '<label class="x-form-item-label" style="width: auto; margin: 0 5px;">'
+ 'Label 1:</label>'
,cls: 'x-form-item'
},{
xtype: "textfield"
},{
xtype: 'box'
,html: '<label class="x-form-item-label" style="width: auto; margin: 0 5px;">'
+ 'Label 2:</label>'
,cls: 'x-form-item'
},{
xtype: "textfield"
}]
});
});
Of course, it would be cleaner to create a CSS class for the custom styles, or even extend a new component from BoxComponent.
You can also generalize this logic in the parent panel's initComponent method, to create box components for the labels from the configured fieldLabel of the field (this way you could also set the for attribute of the label tag because you'll know the generated id of the field components at this time).
change the layout type to form,
Ext.onReady(function(){
var panel = new Ext.Panel({
title:"HBox Panel",
layout:'form',
width:300,
height:200,
renderTo:document.body,
items:[
{
xtype:"textfield",
fieldLabel:"Label1"
},
{
xtype:"textfield",
fieldLabel:"Label2"
}
]
});
});

how to focus on the first tab, when having a few tabs

var tabs = Ext.widget('tabpanel', {
renderTo: 'tabs',
resizeTabs: true,
enableTabScroll: true,
width: 600,
height: 250,
defaults: {
autoScroll: true,
bodyPadding: 10
},
items: [{
title: 'Tab 1003',
iconCls: 'tabs',
//ref:'http://www.yahoo.com',
//hrefTarget:'_self',
html: '<div style="width:100%; height:100%; background-color:#cccccc;"><iframe src="http://www.w3schools.com" frameborder=0 style="width:100%; height:100%;"></iframe></div>',
closable: true,
focusOnToFront : true
}],.........................
how to focus on the first tab, when having a few tabs?
i use focusOnToFront,but it's seen doesn't working.
Seeing that you already have your tabpanel defined in the variable tabs, if you want to make your first tab visible the easiest way would be this:
tabs.setActiveTab(0);
As covered here in the docs.
Add the activeTab property:
var tabs = Ext.widget('tabpanel', {
activeTab: 0,
...

ExtJs - border layout - splitter config

My panel with border layout looks like this:
var oSplitPanel = Ext.create('Ext.panel.Panel', {
lid : 'splitpanel',
layout: 'border',
border: 0,
style: { border: 0 }
height: 150,
items: [{
split: true,
flex: 1,
region: 'west',
xtype: 'panel',
lid: 'panelwest',
layout: 'fit',
minWidth: 200
}]
});
Then another panel gets added to this west region panel:
oSplitPanel.query('[lid=panelwest]')[0].add(oExplorerPanel);
Then this split panel gets added to my main view:
that.getView().add(oSplitPanel);
Then in another function, I add the center panel:
var oAddPanelRight = {
split: true,
flex: 3,
region: 'center',
xtype: 'panel',
lid: 'panelcenter',
layout: 'fit',
border: 0
};
oSplitPanel.add(oAddPanelRight);
Problem:
Everything works perfect this way, however I want to change (limit) the splitter's own width (this splitter is in between west and center panels to resize their width).
What I tried:
Try to change the width of splitters:
listeners: {
afterrender: function() {
// error following, 'splitters' does not exist
oSplitPanel.layout.splitters.west.setWidth(1);
oSplitPanel.doLayout();
}
}
Adding a negative margin to the center panel:
// Tried this:
margin: '0 0 0 -4'
// And that:
style: {
border: 0,
marginLeft: '-3px'
}
Or use event "add"
listeners: {
add: function (me, item) {
if (item.xtype == 'bordersplitter') item.width = 2;
}
},
Demo here http://ext4all.com/post/extjs-4-border-layout-splitter-width
Your oSplitPanel object/instance does not have the split param set to true and has therefor no splitter applied. The splitter get applied to oAddPanelRight object/instance and the nested panel of the oSplitPanel, maybe also to the panel you add later. Can't tell that.
So you just looked at the wrong class.
Btw. to get a splitter for the class itself you don't need look at oSplitPanel.layout.splitters Just look at the splitter prop of the class.

Create a window browser inside the browser with extjs

I'm trying to create a mini browser inside a window using extJS.
Here's what i have so far :
panelContent = new Ext.Panel({
region: 'center',
margins: '0 0 0 0',
autoScroll: true,
html: '<iframe style="overflow:auto;width:100%;height:100%;" frameborder="0" src="http://www.google.com"></iframe>'
});
var tb = new Ext.Toolbar();
var combo = new Ext.form.ComboBox({
width:435,
});
tb.addField(combo);
tb.doLayout();
browser = new Ext.Window({
title: 'Internet Browser',
tbar: tb,
closable: true,
closeAction: 'hide',
width: 600,
height: 600,
border:false,
plain: true,
layout: 'border',
items: [panelContent],
});
I'm trying to get the iframe load the content of what's typed inside the combobox, but i can't find out how to 'tell' him to load a page, and i could not even 'get' when the user hits 'enter'. Maybe replacing the combobox by inputbox ? don't know how to do this (starting with extjs).
Thank you for your help.
You can try this:
Ext.IframeWindow = Ext.extend(Ext.Window, {
onRender: function() {
this.bodyCfg = {
tag: 'iframe',
src: this.src,
cls: this.bodyCls,
style: {
border: '0px none'
}
};
Ext.IframeWindow.superclass.onRender.apply(this, arguments);
}
});
var w = new Ext.IframeWindow({
id:id,
width:640,
height:480,
title:"Knowledge Control Solutions Iframe Window Sample",
src:"http://www.google.es"
})
w.show();
Regards
If you're serious about working with iframes in Ext JS you really should be using the ManagedIFrame user extension. Working with a raw iframe within Ext (especially inside layouts) is not the easiest thing to try and do from scratch.

Resources