Maximize, minimize extjs panel - extjs

How can we add maximize and minimize in the panel of EXTJS 4 portal example:
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/portal/portal.html
Fully working code:
Ext.define('Ext.app.Portal', {
extend: 'Ext.container.Viewport',
requires: ['Ext.app.PortalPanel', 'Ext.app.PortalColumn', 'Ext.app.GridPortlet', 'Ext.app.ChartPortlet'],
initComponent: function(){
var content = '<div class="portlet-content">'+Ext.example.shortBogusMarkup+'</div>';
var mainColumnPanelId;
//var mainPanelId;
var itemNo=0;
this.tools= [
{
type:'minimize',
hidden:true,
scope:this,
handler: function(e, target, panel)
{
var cardPanel=Ext.getCmp("app-portal");
var c = panel.up("viewport");
var maximizePortletPanel = Ext.getCmp("maximizePortletPanel");
cardPanel.layout.setActiveItem(0);
var originalPanel=Ext.getCmp(mainColumnPanelId);
originalPanel.insert(itemNo,maximizePortletPanel.items.items[0]);
panel.tools['close'].setVisible(true);
panel.tools['collapse-top'].setVisible(true);
panel.tools['minimize'].setVisible(false);
panel.tools['maximize'].setVisible(true);
}
},
{
type:'maximize',
scope:this,
handler: function(e, target, panel)
{
var cardPanel=Ext.getCmp("app-portal");
var columnPanel = panel.ownerCt.ownerCt;
var maximizePortletPanel = Ext.getCmp("maximizePortletPanel");
mainColumnPanelId=columnPanel.getId();
var columnPanelItems=columnPanel.items.items;
for(var j=0;j<columnPanelItems.length;j++){
if(columnPanelItems[j].getId()==panel.ownerCt.getId()){
itemNo=j;
break ;
}
}
maximizePortletPanel.insert(0,panel.ownerCt);
cardPanel.layout.setActiveItem(1);
panel.tools['minimize'].setVisible(true);
panel.tools['close'].setVisible(false);
panel.tools['collapse-top'].setVisible(false);
panel.tools['maximize'].setVisible(false);
}
}];
Ext.apply(this, {
id: 'app-viewport',
layout: {
type: 'border',
padding: '0 5 5 5' // pad the layout from the window edges
},
items: [{
id: 'app-header',
xtype: 'box',
region: 'north',
height: 40,
html: 'Ext Portal'
},{
xtype: 'container',
region: 'center',
layout: 'border',
items: [{
id: 'app-options',
title: 'Options',
region: 'west',
animCollapse: true,
width: 200,
minWidth: 150,
maxWidth: 400,
split: true,
collapsible: true,
layout:{
type: 'accordion',
animate: true
},
items: [{
html: content,
title:'Navigation',
autoScroll: true,
border: false,
iconCls: 'nav'
},{
title:'Settings',
html: content,
border: false,
autoScroll: true,
iconCls: 'settings'
}]
},{
id: 'app-portal',
region: 'center',
layout:'card',
items:[{
xtype: 'portalpanel',
items: [{
id: 'col-1',
items: [{
id: 'portlet-1',
title: 'Grid Portlet',
tools: this.tools,
items: Ext.create('Ext.app.GridPortlet'),
listeners: {
'close': Ext.bind(this.onPortletClose, this)
}
},{
id: 'portlet-2',
title: 'Portlet 2',
tools: this.tools,
html: content,
listeners: {
'close': Ext.bind(this.onPortletClose, this)
}
}]
},{
id: 'col-2',
items: [{
id: 'portlet-3',
title: 'Portlet 3',
tools: this.tools,
html: '<div class="portlet-content">'+Ext.example.bogusMarkup+'</div>',
listeners: {
'close': Ext.bind(this.onPortletClose, this)
}
}]
},{
id: 'col-3',
items: [{
id: 'portlet-4',
title: 'Stock Portlet',
tools: this.tools,
items: Ext.create('Ext.app.ChartPortlet'),
listeners: {
'close': Ext.bind(this.onPortletClose, this)
}
}]
}]
},{ //title: 'Portlet',
xtype:'panel',
id:'maximizePortletPanel',
layout:'fit',
autoScroll:true
//border:true,
//frame:true
}]////
}]//
}]
});
this.callParent(arguments);
},
onPortletClose: function(portlet) {
this.showMsg('"' + portlet.title + '" was removed');
},
showMsg: function(msg) {
var el = Ext.get('app-msg'),
msgId = Ext.id();
this.msgId = msgId;
el.update(msg).show();
Ext.defer(this.clearMsg, 3000, this, [msgId]);
},
clearMsg: function(msgId) {
if (msgId === this.msgId) {
Ext.get('app-msg').hide();
}
}
});

You cannot 'maximize' or 'minimize' the 'Viewport' because it automatic render to body, If you want to use maximize/minimize feature you must work with Window that is the better way to do.
The Viewport renders itself to the document body, and automatically
sizes itself to the size of the browser viewport and manages window
resizing. There may only be one Viewport created in a page.
See: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.container.Viewport
But if you want to maximize some panel inside the viewport you should use showBy method of each panel to show it by the specified size with target component.
See: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.window.Window-method-showBy

You can push panel as item inside Window. Then provide maximize and minimize functionality by using tool[tbar in extjs].

Related

Add input field in Ext.tab.Panel

I am creating a menu using Ext.tab.Panel and would like to have Search feature. Something like Bootstrap navbar - https://getbootstrap.com/docs/4.0/components/navbar/
I tried to simply add the textfield element but didn't work obviously.
Ext.create('Ext.TabPanel', {
fullscreen: true,
items: [{
title: 'Home',
iconCls: 'home',
html: 'Home Screen'
},
{
title: 'Contact',
iconCls: 'user',
html: 'Contact Screen'
},
{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
allowBlank: false // requires a non-empty value
}
]
});
Is it possible to achieve this at all?
You can archive it with the tabbar config of the Ext.tab.Panel.
The Ext.tab.Bar is a specialized Ext.container.Container where you can add items like a to Textfield.
So add te search textfield to the tabbar config and you can archive what you want to, see the example code below and the Sencha Fiddle.
Ext.create('Ext.TabPanel', {
fullscreen: true,
items: [{
title: 'Home',
iconCls: 'home',
html: 'Home Screen'
},
{
title: 'Contact',
iconCls: 'user',
html: 'Contact Screen'
},
],
tabBar: {
items: [
{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
allowBlank: false // requires a non-empty value
}
]
},
renderTo: Ext.getBody()
});
At first this functionality does not exist in the tabpanel, which I recommend you do and replace the idea of ​​tabpanel to apply a cardlayout which is the same tabpanel layout system.
And then you can use a toolbar, with the buttons being configured with the toogleGroup, in short, you'd better see the code example below working.
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.Panel', {
fullscreen: true,
renderTo: Ext.getBody(),
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'toolbar',
height: 42,
defaults: {
xtype: 'button',
},
items: [{
text: 'Tab1',
handler: function(button){
var me = this,
fakeContainer = button.up('panel').down('#fakeTab');
fakeContainer.setActiveItem(button.tabIndex);
},
tabIndex: 0,
toggleGroup: 'tabHandler',
enableToggle: true,
pressed: true,
margin: '0'
}, {
text: 'Tab2',
handler: function(button){
var me = this,
fakeContainer = button.up('panel').down('#fakeTab');
fakeContainer.setActiveItem(button.tabIndex);
},
tabIndex: 1,
enableToggle: true,
margin: '0'
}, {
text: 'Tab3',
handler: function(button){
var me = this,
fakeContainer = button.up('panel').down('#fakeTab');
fakeContainer.setActiveItem(button.tabIndex);
},
tabIndex: 2,
toggleGroup: 'tabHandler',
enableToggle: true,
margin: '0'
}, '->', {
xtype: 'textfield',
fieldLabel: 'Search:',
labelWidth: 70,
width: 250,
margin: 0
}, {
iconCls: 'x-fa fa-search',
handler: function(){
alert('Your Search here!');
}
}]
}, {
xtype: 'container',
itemId: 'fakeTab',
margin: '16 0 0 0',
flex: 1,
layout: 'card',
defaults: {
xtype: 'container',
height: 800
},
items: [{
html: '<STRONG>TAB 1 your content here</STRONG>'
}, {
html: '<STRONG>TAB 2 your content here</STRONG>'
}, {
html: '<STRONG>TAB 3 your content here</STRONG>'
}]
}]
});
}
});
Working sample here

How to add accordian items dynamically?

I have view like this :
Ext.define('Example.demo.CycleInfo', {
extend: 'Ext.panel.Panel',
requires:[
'Ext.layout.container.Accordion'
],
xtype: 'cycleinfo',
title: 'All Data',
defaults: {
frame: true,
bodyPadding: 5
},
initComponent: function() {
data = this.data
Ext.apply(this, {
items: [{
layout: 'accordion',
frame: true,
bodyPadding: 5,
items: [{
xtype:'structure'
},
{
title: 'Requests',
html: 'Empty'
}]
}]
});
this.callParent();
}
});
Here there are two accordian (one included item and other Requests) they are static .. I want based on this.data value(contains length) It should have accordian in the inner items. How should I do it.
If you want to add more panels to your main container with accordion layout, this should work:
Ext.define('Example.demo.CycleInfo', {
extend: 'Ext.panel.Panel',
requires:[
'Ext.layout.container.Accordion'
],
xtype: 'cycleinfo',
title: 'All Data',
defaults: {
frame: true,
bodyPadding: 5
},
initComponent: function() {
me = this;
Ext.apply(me, {
items: [{
layout: 'accordion',
frame: true,
bodyPadding: 5,
items: [{
title: 'Testing...',
html: 'This is a test panel'
},{
title: 'Requests',
html: 'Empty'
}]
}],
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
ui: 'footer',
items: ['->',{
text: 'Add panel',
handler: function() {
this.up().up().down('panel').add({
title: 'New Panel',
html : 'New Content'
})
}
}]
}]
});
this.callParent();
}
});
Ext.create('Example.demo.CycleInfo',{
renderTo: Ext.getBody(),
width: 500,
height: 500
});
Ext.define('CycleInfo', {
extend: 'Ext.panel.Panel',
requires:[
'Ext.layout.container.Accordion'
],
xtype: 'cycleinfo',
title: 'All Data',
width : 400,
height : 500,
defaults: {
frame: true,
bodyPadding: 5
},
layout: 'accordion',
initComponent: function() {
this.tbar = [{
text : 'Add Panel To Accordion',
handler : function(){
this.add({
xtype:'panel',
html: 343434
});
},
scope:this
}];
this.callParent();
}
});
Ext.create('CycleInfo',{renderTo:Ext.getBody()});
In your case you must change **xtype** in initComponent all is well

how to create ExtJs 4 Tree inside accordion using store?

I have an application with possibly 4 level menu,
i want to implement it with Accordion for first level and a tree inside each accordion panel.
how could i implement this with a store?
http://i.stack.imgur.com/DFQDl.png
Here is the working example :
ExtJS - Treepanel inside the Accordion Menu
Ext.onReady(function () {
Ext.create('Ext.panel.Panel', {
title: 'Accordion Layout',
width: 300,
height: 300,
defaults: {
// applied to each contained panel
bodyStyle: 'padding:15px'
},
layout: {
// layout-specific configs go here
type: 'accordion',
titleCollapse: false,
animate: true,
activeOnTop: true
},
items: [{
title: 'Panel 1',
id: 'panelOne',
html: 'Panel content!'
}, {
title: 'Panel 2',
html: 'Panel content!'
}, {
title: 'Panel 3',
html: 'Panel content!'
}],
renderTo: Ext.getBody()
});
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "detention", leaf: true },
{ text: "homework", expanded: true, children: [
{ text: "book report", leaf: true },
{ text: "algebra", leaf: true}
] },
{ text: "buy lottery tickets", leaf: true }
]
}
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
id: 'treePanel',
header: false,
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});
var panel = Ext.getCmp('panelOne');
var tree = Ext.getCmp('treePanel');
panel.add(tree);
});
Ali,
here is the modified edition, hope it's right!
ExtJS - TreePanel inside the Panel
Ext.define('AccModel', {
extend: 'Ext.data.Model',
fields: ['id','text']
});
var accordion = Ext.create('Ext.panel.Panel', {
width: 400,
height: 620,
id: 'accordionPanel',
defaults: {
bodyStyle: 'padding:15px'
},
layout: {
type: 'accordion',
titleCollapse: false,
animate: true,
activeOnTop: false
},
renderTo: Ext.getBody()
});
var addAccordion = function() {
Ext.Ajax.request({
url: 'treenode.json',
success: function(response) {
var nodes = Ext.JSON.decode(response.responseText);
Ext.each(nodes, function(node) {
accordion.add({
title: node.id,
id: node.id,
items: Ext.create('Ext.tree.Panel', {
header: false,
width: 380,
height: 600,
rootVisible: false,
root: {
expanded: false,
children: node.children
}
})
});
})
}
});
}
var init=function() {
addAccordion();
}
Ext.onReady(function () {
init();
});

get active tab on button click in extjs

I just want to get active tab on 'save' button click in extjs code.
my code is given below:
Ext.require([
'Ext.tab.*',
'Ext.window.*',
'Ext.tip.*',
'Ext.layout.container.Border'
]);
Ext.define('WebCare.UI.RoleManagerAdminWindow', {
extend: 'Ext.window.Window',
id: 'rolemanageradminwindow',
modal: true,
title: 'Manage Role & Permission',
closable: true,
closeAction: 'hide',
width: 600,
height: 550,
minWidth: 700,
minHeight: 200,
layout: 'border',
bodyStyle: 'padding: 5px;',
listeners: {
show: function (sender, eOpts) {
var self = sender;
vent.trigger("WindowLoad");
}
},
items: [
{
id: 'rolemanageradmintab',
region: 'center',
xtype: 'tabpanel',
constructor: function (config) {
var self = this;
self.callParent(config);
},
items: [
{
xtype: 'rolemanagereditor',
id:'1'
},
{
xtype: 'agencyeditor',
id: '2'
}
],
listeners: {
'tabchange': function (tabPanel, tab) {
}
}
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
ui: 'footer',
defaults: { minWidth: 70 },
style: {
background: "#d6e3f3"//, "#d9ebff",
},
height: 40,
items: [
{ xtype: 'component', flex: 1 },
Ext.create('Ext.button.Button', {
height: 25,
text: 'Close',
disabled: false,
handler: function () {
this.up('.window').close();
}
}),
Ext.create('Ext.button.Button', {
height: 25,
text: 'Save',
disabled: false,
handler: function () {
}
})
]
}
]
});
A simple example to get the active tab in the tabpanel when you click Save button.
Ext.onReady(function() {
var tabPanel = Ext.create('Ext.tab.Panel', {
width: 300,
height: 200,
activeTab: 0,
items: [
{
title: 'Tab 1',
bodyPadding: 10,
html: 'A simple tab'
},
{
title: 'Tab 2',
html: 'Another one'
},
{
title: 'Tab 3',
html: 'Another one'
}
],
buttons: [
{
text: 'Save',
handler: function() {
var activeTab = tabPanel.getActiveTab();
alert("The active tab in the panel is " + activeTab.title);
}
}
],
renderTo: Ext.getBody()
});
});

Formpanel not visible in tabview

Here my code in sencha for my applicaiton,I have included table and two buttons in resetpanel and addded into tab view
var tab= Ext.create('Ext.List', {
fullscreen: true,
dock: 'left',
width: 320,
height: 200,
ui: 'round',
store: {
fields: ['ext_xtype'],
data: [{
ext_xtype: 'fieldset',
}, {
ext_xtype: 'formpanel',
}]
},
itemTpl: '<span style="width:300px; display:inline-block;">{ext_xtype}</span> '
});
var resetPanel1 = new Ext.form.FormPanel({
id: 'resetPanel1',
style:{background:'#D8D8D8'},
dockedItems:[]
,
items: [tab,{
xtype: 'button',
text: 'Add',
ui: 'confirm',
handler: function() {
view.setActiveItem('welcomepanel', {type:'fade', direction:'left'});
}
},{
xtype: 'button',
text: 'Add',
ui: 'Search',
handler: function() {
view.setActiveItem('welcomepanel', {type:'fade', direction:'left'});
}}]});
var view = Ext.create('Ext.TabPanel', {
fullscreen: true,
tabBarPosition: 'bottom',
scroll:'vertical',
items: [{
title: 'ITEMS',
iconCls: 'star',
layout:'card',
items: [{
docked: 'top',
xtype: 'titlebar',
title: 'Add Items',
},resetPanel1
]
}]
});
Ext.Viewport.add(view);
}
});
The resetPanel1 is not viewing in tab view.Whats wrong with my code.Please help me to sort it out.
Remove the fullscreen and dock properties from the list, you should have fullscreen : true only in the main view, In your case TabPanel.
var tab= Ext.create('Ext.List', {
width: 320,
height: 200,
ui: 'round',
store: {
fields: ['ext_xtype'],
data: [{
ext_xtype: 'fieldset',
},{
ext_xtype: 'formpanel',
}]
},
itemTpl: '<span style="width:300px; display:inline-block;">{ext_xtype}</span>'
});

Resources