adding panel within panel dynamically with autoadjust - extjs

I want to add panels within a panel dynamically, since i dont know upfront the numbers of panels which i need to add.
This works fine if i do
panel.insert(<panel to be added>);
The parent panel is configured with the hbox layout.
But if the overall width of added panels goes beyond the parent panel width then there is a overflow and a horizontal scrollbar appears.
Rather what i am looking is it should add the panels to the next line automatically if it reaches the parent panels width.
Any solution to the above problem, might be i need to use some other layout here but not sure on that.
Thanks

I have one idea but you should try in your code then let me know the result. Basically, set layout type to auto.
var resultsPanel = Ext.create('Ext.panel.Panel', {
title: 'Results',
width: 600,
height: 400,
id: 'panel_one',
renderTo: Ext.getBody(),
layout: {
type: 'auto', // Arrange child items vertically
align: 'stretch', // Each takes up full width
padding: 5
}
});
var opanel = Ext.getCmp('panel_one');
console.log(opanel);
opanel.add([
{
xtype: 'panel',
title: 'Inner Panel',
width: Ext.getCmp('panel_one').getWidth(),
height: 100
}
]);
opanel.add([
{
xtype: 'panel',
title: 'Inner Panel',
width: Ext.getCmp('panel_one').getWidth()
height: 100
}
]);

Parent panel layout should be Table with number of columns specified.
See the following code for parent panel
{
xtype: 'panel',
itemId: 'productListPanel',
height: 500,
width: 600,
layout: {
type: 'table',
columns: 3
},
autoScroll: true
}
now i can add any number of child panels to it, see the following code.
for (var i = 0; i < 10; i++) {
var panel = Ext.create('Ext.panel.Panel', {
width: 190,
height: 150,
padding: 10,
cls: 'myPanel',
title: "Child Panle"+i
});
parentPanel.insert(panel);
}
This solved my problem, hope it helps somebody.
Thanks

Related

ExtJS: Display image in window

Displaying image in a window sounds a simple task but i have problem with it.
I want to show my image (with variable size) to show in a window (or panel) with size 300*400. Then, by clicking on image or maximizing window, user sees image in its original size.
Following code works for stretching image to 300*400 thumbnail in initial view, but when maximizing it also stretches to full screen.
var myImage = Ext.create('Ext.Img', {
src: imgSrc,
});
picWin = Ext.create('Ext.window.Window', {
title: "My Picture",
width: 300,
height: 400,
maximizable: true,
maxWidth: myImage.getWidth(),
maxHeight: myImage.getHeight(),
layout: "fit",
items: [myImage]
})
picWin.show();
Take a look at my example: https://fiddle.sencha.com/#view/editor&fiddle/26eo
Seems to work. I removed the set max width and height.
Finally, i came to a solution like this. First we need to use card layout. Then we define two containers for specified image, one for initial view and one for maximized view. At last, we need to change these cards when window is maximized and when restored.
Code is as follows:
// Two image for when maximizing and when in initial view
var myImage = Ext.create('Ext.container.Container', {
layout: 'fit',
items: [{
xtype: 'image',
src: imgSrc
}]
});
var myImage2 = Ext.create('Ext.container.Container', {
scrollable: true,
items: [{
xtype: 'image',
src: imgSrc
}]
});
picWin = Ext.create('Ext.window.Window', {
title: "my title",
width: 300,
height: 400,
maximizable: true,
layout: "card",
activeItem: 0,
items: [myImage,myImage2],
listeners: {
maximize: function(){
this.setActiveItem(1);
},
restore: function(){
this.setActiveItem(0);
},
}
})
picWin.show();
What if we changed the layout from 'fit' to 'hbox' instead? This seems to give you what you want - when the window is maximised, the image does not stretch. Center and vbox also seemed to work, so there are probably a few layouts you could use to make it work. But since you only have an image in the window, it probably doesn't matter.
picWin = Ext.create('Ext.window.Window', {
title: "My Picture",
width: 300,
height: 400,
maximizable: true,
layout: "hbox",
items: [myImage]
})
picWin.show();
}

ExtJS: 'next to centre'

I'd like to achieve this in ExtJS 4.2:
e.g. a centred button, with something (a progress indicator) to its right that doesn't result in the button moving.
All my layouts are currently relative, largely using HBox & VBox, and I'd like to keep it this way rather than using anything absolute to solve this.
There are probably lots of ways to do this, but many of them will be horrible. I guess the 'floating' attribute might play a part, but I can't quite work that out.
Any suggestions?
Use the HBox layout's pack config to display the items in the center, and apply a margin equal to the progess bar's width to the left side of the button:
{
layout: {
type: 'hbox',
pack: 'center'
},
items: [{
xtype: 'button',
text: 'Push me',
width: 100,
margin: '0 0 0 100' // margin-left equal to the width of the progress bar
},{
xtype: 'progressbar',
width: 100
}]
}
Also check out this fiddle.
Here is my attempt, let me know if it's a problem.
Ext.onReady(function() {
var ct = new Ext.panel.Panel({
width: '100%',
renderTo: Ext.getBody(),
margin: 10,
border: true,
id: 'ppanel',
layout: {
type: 'hbox',
},
items: [{
xtype: 'button',
text: 'Push me',
width: 100,
id: 'bbutton'
},{
xtype: 'progressbar',
width: 100,
id: 'pbar'
}],
listeners: {
afterrender: function() {
pwidth = Ext.getCmp('ppanel').getWidth();
bwidth = Ext.getCmp('bbutton').getWidth();
button = Ext.getCmp('bbutton');
progrs = Ext.getCmp('pbar');
bmargin = (pwidth/2 - bwidth/2);
button.setMargin("0 0 0 "+bmargin);
progrs.setMargin("0 0 0 10");
}
}
});
});

positioning of a container in extjs

In my project, I am trying to position a container as absolute. but if I do so, it is also effecting the neighbour items. I mean, after positioning the container, if I give some width and height to that particular container, it is effecting all the toolbar. (which I don't want to happen). This effect is happening even if I use layout: 'absolute or css position:absolute.
Here is my related code:
xtype: 'panel',
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
height: 40,
items: [
{
//only this should be absolute positioned
xtype: 'container',
cls: 'logo', //tried with applying css styles !important
//even tried with layout: 'absolute'
},'-',
//the below elements should not move their position
//even if the above one has been applied positioning.
{
xtype: 'container'
},'->',
{
xtype: 'container'
}]
}],
Here my goal is to bring the container out of the toolbar because it should have greater height than the toolbar keeping other containers constant.
If the profile pic container has to be higher than the toolbar, it can't be a child of the toolbar container.
You could create a container with absolute layout below the toolbar, in that container you will have the profile pic and you can use a negative Y variable in order to move up the image, so it looks like is in the toolbar.
Just like this
var toolbar = Ext.create('Ext.toolbar.Toolbar', {
items: [
{},
{ xtype: 'tbspacer', width: 50 }, // Moving the button to the right
{ text: 'Fake Name Button' }
]
});
Ext.create('Ext.container.Container', {
layout: 'fit',
width : 700,
renderTo: Ext.getBody(),
items: [toolbar]
});
var image = Ext.create('Ext.Img', {
x: 0,
y: -25,
maxWidth: 70,
src: 'https://twimg0-a.akamaihd.net/profile_images/1471554494/swel.png'
});
Ext.create('Ext.container.Container', {
layout: {
type: 'absolute'
},
renderTo: Ext.getBody(),
items: [image]
});
http://jsfiddle.net/alexrom7/33cP8/1/
This solution is not so pretty, but it might work.

How to set a dynamic width in an vbox in ExtJS4?

I want the following layout (the chart count in the top right is dynamic):
I tried to take a border-layout for the main container. Chart1 is region: 'west' and the rest is in region: 'center'.
In the center, I got a vbox container, with 2 containers, one for the charts (top) and one is the grid (bottom)
The Problem is now, that these 2 containers want a fixed width, or else they get a zero width...
Also I want to have all the containers to be fluid, so I can resize everything without getting empty spaces.
I read about using flex: 1 if I want some containers in a vbox to to get a 100% width, but this didn't work. It just made the 2 containers in the vbox use the same height.
Any ideas?
How about something like this (quickly drawn in the architect):
Ext.define('MyApp.view.MyWindow', {
extend: 'Ext.window.Window',
height: 600,
width: 1000,
layout: {
align: 'stretch',
type: 'hbox'
},
title: 'My Window',
initComponent: function () {
var me = this;
Ext.applyIf(me, {
items: [{
xtype: 'container',
flex: 1,
layout: {
type: 'fit'
},
items: [{
xtype: 'chart'
}]
}, {
xtype: 'container',
flex: 4,
layout: {
align: 'stretch',
type: 'vbox'
},
items: [{
xtype: 'container',
flex: 1,
layout: {
align: 'stretch',
type: 'hbox'
},
items: [{
xtype: 'chart',
flex: 1,
}, {
xtype: 'chart',
flex: 1,
}, {
xtype: 'chart',
flex: 1,
}, {
xtype: 'chart',
flex: 1,
}]
}, {
xtype: 'gridpanel',
flex: 1,
title: 'My Grid Panel',
}]
}]
});
me.callParent(arguments);
}
});
Although that way the Flex value of the second container has to account for the amount of charts you're displaying horizontally.
Have you tried table layout? It's quite easy to create such layout with it. Example:
Ext.onReady(function(){
Ext.create('Ext.Viewport', {
renderTo: Ext.getBody(),
style: 'border: 1px solid red',
layout: {
type: 'table',
columns: 5,
tdAttrs: {
style: 'padding: 20px; border: 1px solid blue;'
}
},
defaults: {
bodyStyle: 'border: 1px solid red'
},
items: [
{ xtype: 'panel', html: 'Chart1', rowspan: 2 },
{ xtype: 'panel', html: 'Chart2' },
{ xtype: 'panel', html: 'Chart3' },
{ xtype: 'panel', html: 'Chart4' },
{ xtype: 'panel', html: 'Chart5' },
{ xtype: 'panel', html: 'Grid', colspan: 4 }
]
});
});
Working sample: http://jsbin.com/ojijax/1/
To have dynamic layout IMO the best solution is to use hbox and vbox layouts.
For example you can wrap charts from 2 to n into one container, let's say chartPanel - this will have hbox layout. Then wrap chartPanel and grid into another container - panel with vbox layout. Then again wrap chart1 with panel with hbox layout. Then you must set align: stretch for each box layout, and proper flex to divide screen equaly.
Working sample: http://jsfiddle.net/75T7h/
I think you are loading chart2, 3, 4 , 5 in a for loop using panel.add option of extjs (better way).
If so then keep a count of these panels (here 4) and for each panel while assigning width you give like
width:(1/countOfchrtLIst2345) * grid.getWidth(),
So whatever count comes it will divide available width between all these horizontal panels within your top vbox and allocates.
In your example it assigns
(1/4) * 200
(thinking grid has width of 200)

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.

Resources