load grid panel into content panel - extjs

I try to understand the basics of the extjs MVC.
I created the example app with the Sencha CMD. This comes with some basic things. What i try to make is a panel with a toolbar where i have a menu. When i click on a item in the menu i want to load a grid into the panel.
What function do i need to do this?
This is my mainmodel
Ext.define('JustRent.view.main.Main', {
extend: 'Ext.container.Container',
requires: [
'JustRent.view.main.MainController',
'JustRent.view.main.MainModel',
'JustRent.view.main.ProductenType'
],
xtype: 'app-main',
controller: 'main',
viewModel: {
type: 'main'
},
layout: {
type: 'border'
},
items: [{
region: 'center',
id: 'contentBlock',
xtype: 'panel',
layout: 'fit',
title: 'JustRental',
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'button',
text: 'Menu',
menu: {
xtype: 'menu',
items: [{
xtype: 'menuitem',
text: 'verhuur',
menu: {
xtype: 'menu',
items: [{
xtype: 'menuitem',
text: 'Offertes',
menu: {
xtype: 'menu',
items: [{
xtype: 'menuitem',
text: 'Overzicht'
},{
xtype: 'menuitem',
text: 'Nieuwe offerte'
},{
xtype: 'menuitem',
text: 'Openstaande offertes'
},{
xtype: 'menuitem',
text: 'Geannuleerde offertes'
}]
}
}, {
xtype: 'menuitem',
text: 'Projecten',
menu: {
xtype: 'menu',
items: [{
xtype: 'menuitem',
text: 'Overzicht'
}]
}
}, {
xtype: 'menuitem',
text: 'Producten',
menu: {
xtype: 'menu',
items: [{
xtype: 'menuitem',
text: 'Overzicht'
},{
xtype: 'menuitem',
text: 'Artikelen'
},{
xtype: 'menuitem',
text: 'Groepen'
},{
xtype: 'menuitem',
text: 'Type',
handler: 'onClickButton',
},{
xtype: 'menuitem',
text: 'Soort'
},{
xtype: 'menuitem',
text: 'Merk'
}]
}
}, {
xtype: 'menuitem',
text: 'Klanten'
}]
}
},
{
xtype: 'menuitem',
text: 'verkoop'
}
]
}
}]
}]
}
]
});
when i click on an item i use a basic handler. This is located in my mainController file:
Ext.define('JustRent.view.main.MainController', {
extend: 'Ext.app.ViewController',
requires: [
],
alias: 'controller.main',
onClickButton: function () {
console.log('click works');
}
});
this is my ProductenType
Ext.define('JustRent.view.main.ProductenType', {
extend: 'Ext.grid.Panel',
alias: 'widget.ProductenType',
requires: [
// alerts
],
xtype: 'gridpanel',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'string',
text: 'String'
},
{
xtype: 'numbercolumn',
dataIndex: 'number',
text: 'Number'
},
{
xtype: 'datecolumn',
dataIndex: 'date',
text: 'Date'
},
{
xtype: 'booleancolumn',
dataIndex: 'bool',
text: 'Boolean'
}
]
});
but now is my question how can i load the JustRent.view.main.ProductenType into the panel with the id 'contenBlock'.

I would use a Viewport as my main container
http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.container.Viewport
with a border layout http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.layout.container.Border
and then use add http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.container.Viewport-method-add
and remove methods http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.container.Viewport-method-remove
for component manipulation within the Viewport
pro tip: avoid unnecessary over nesting of components, use the lighter Component possible in each case. e.g containers are lighter in the DOM compared to panels so if you only need a container don't use a panel (not saying this is the case) .
Also I recommend Extjs in Action, awesome book that will help you really understand the framework.

Related

Extjs 6.5+ Adding Components to Container Gives Empty Viewport

Not sure why I'm getting an empty viewport. I am defining subclasses as components and trying to get the viewport to display the 2 components created. Seems simple enough yet coming up empty?
Ext.define('MyApp.view.MyHeader', {
extend: 'Ext.Container',
items: [{
xtype: 'titlebar',
title: 'Logo',
titleAlign: 'left',
cls: 'im-titlebar',
dock: 'top',
id: 'titlebar',
items: [
{
xtype: 'button',
text: 'Log In',
align: 'right',
ui: 'action',
margin: '',
ariaRole: 'button',
cls: 'btn-im-login action noprint',
id: 'button_LogIn'
}
]
}]
});
Ext.define('MyApp.view.MyFooter', {
extend: 'Ext.Container',
items: [{
xtype: 'container',
items: [{
xtype: 'button',
text: 'Button',
align: 'right',
ui: 'action',
ariaRole: 'button',
cls: 'btn-im-login action noprint',
id: 'button_Button'
}]
}]
});
Ext.define('MyApp.view.MyView', {
extend: 'Ext.Container',
requires: ['MyApp.view.MyHeader', 'MyApp.view.MyFooter']
});
Ext.Loader.setConfig({
enabled: false
});
Ext.application({
name: 'MyApp',
launch: function () {
Ext.Viewport.add(Ext.create('MyApp.view.MyView'));
}
});
See fiddle
You're trying to require views, but you should add it to parent view by items array.
Ext.define('MyApp.view.MyHeader', {
extend: 'Ext.Container',
xtype: 'myheader',
items: [{
xtype: 'titlebar',
title: 'Logo'
}]
});
Ext.define('MyApp.view.MyFooter', {
extend: 'Ext.Container',
xtype: 'myfooter',
items: [{
xtype: 'container',
items: [{
xtype: 'button',
text: 'Button'
}]
}]
});
Ext.define('MyApp.view.MyView', {
extend: 'Ext.Container',
xtype: 'myView',
height: 100,
items: [{
xtype: 'myheader'
}, {
xtype: 'myfooter'
}]
});
Ext.application({
name: 'MyApp',
launch: function () {
Ext.Viewport.add({
xtype: 'myView'
});
}
});
Remember - classic toolkit does not have Ext.Viewport class.
Ext.application({
name : 'MyApp',
launch : function() {
Ext.create({
xtype: 'panel',
renderTo: Ext.getBody(),
bodyPadding: 20,
tbar: {
items: [{
xtype: 'label',
text: 'Header'
}]
},
bbar: {
items: [{
xtype: 'label',
text: 'footer'
}]
},
items: [{
xtype: 'form',
title: 'My Form',
layout: 'form',
items: [{
xtype: 'textfield',
fieldLabel: 'someField'
}]
}]
});
}
});
Your code does what you have defined.
You need to add the Header and Footer components as items.
I would suggest that you may try to to use a panel and / or use tbar, bbar or header configs available there.
docs:
https://docs.sencha.com/extjs/6.2.0/classic/Ext.panel.Panel.html
https://docs.sencha.com/extjs/6.2.0/classic/Ext.panel.Panel.html#cfg-dockedItems
https://docs.sencha.com/extjs/6.2.0/classic/Ext.panel.Panel.html#cfg-header
https://docs.sencha.com/extjs/6.2.0/classic/Ext.panel.Panel.html#cfg-bbar
Ext.application({
name: 'MyApp',
launch: function () {
var f = Ext.create('MyApp.view.MyHeader', {
flex: 1
});
var h = Ext.create('MyApp.view.MyFooter', {
flex: 1
});
Ext.Viewport.add(Ext.create('MyApp.view.MyView', {
layout: {
type: 'vbox',
align: 'stretch'
},
items: [h, f]
}));
}
});

ExtJS 6 - Scrollable GridPanels

I'm working on a Sencha ExtJS 6.5 project. I have two gridpanels, one next to each other, and I need them to be scrollable, but no matter what I try, I can't seem to accomplish that.
I must add that this two gridpanels are inside another panel, which is also within a ViewPort.
This is a picture of what I need:
And this the code I have written so far:
Ext.define('ScrollTest.view.MyViewport', {
extend: 'Ext.container.Viewport',
alias: 'widget.myviewport',
requires: [
'ScrollTest.view.MyViewportViewModel',
'Ext.toolbar.Toolbar',
'Ext.button.Button',
'Ext.grid.Panel',
'Ext.grid.column.Column',
'Ext.view.Table'
],
viewModel: {
type: 'myviewport'
},
layout: 'fit',
items: [
{
xtype: 'panel',
alignOnScroll: false,
border: false,
itemId: 'oMainPanel',
title: 'Familias de Activos',
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
itemId: 'oGridToolbar',
items: [
{
xtype: 'button',
text: 'Agregar Familia'
},
{
xtype: 'button',
text: 'Modificar Familia'
},
{
xtype: 'button',
text: 'Eliminar Familia'
},
{
xtype: 'button',
text: 'Detalle'
}
]
}
],
items: [
{
xtype: 'panel',
layout: {
type: 'hbox',
align: 'stretch'
},
items: [
{
xtype: 'gridpanel',
flex: 1,
alignOnScroll: false,
scrollable: true,
title: 'Familias',
headerBorders: false,
bind: {
store: '{oStore}'
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'id',
text: 'blah blah'
}
],
viewConfig: {
scrollable: 'vertical'
}
},
{
xtype: 'gridpanel',
flex: 1,
alignOnScroll: false,
scrollable: 'vertical',
title: 'Articulos',
bind: {
store: '{oStore2}'
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'id',
text: 'blop blop'
}
]
}
]
}
]
}
]
});
What am I doing wrong? Thank you very much in advance.
You have an unnecessary layer of nesting, there is a panel with no layout defined. Remove it:
Ext.define('ScrollTest.view.MyViewport', {
extend: 'Ext.container.Viewport',
alias: 'widget.myviewport',
layout: 'fit',
items: [{
xtype: 'panel',
border: false,
itemId: 'oMainPanel',
title: 'Familias de Activos',
layout: {
type: 'hbox',
align: 'stretch'
},
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
itemId: 'oGridToolbar',
items: [{
xtype: 'button',
text: 'Agregar Familia'
}, {
xtype: 'button',
text: 'Modificar Familia'
}, {
xtype: 'button',
text: 'Eliminar Familia'
}, {
xtype: 'button',
text: 'Detalle'
}]
}],
items: [{
xtype: 'gridpanel',
flex: 1,
title: 'Familias',
store: {
data: (function() {
var data = [],
i;
for (i = 1; i <= 100; ++i) {
data.push({id: i});
}
return data;
})()
},
columns: [{
dataIndex: 'id',
text: 'blah blah'
}]
}, {
xtype: 'gridpanel',
flex: 1,
title: 'Articulos',
store: {
data: (function() {
var data = [],
i;
for (i = 1; i <= 100; ++i) {
data.push({id: i});
}
return data;
})()
},
columns: [{
dataIndex: 'id',
text: 'blop blop'
}]
}]
}]
});
Ext.application({
name: 'Fiddle',
launch: function () {
new ScrollTest.view.MyViewport();
}
});

Sencha: How to align a label with a textfield?

It seems ridiculous to have to ask this question - but here we go. How do you align a Label with a textfield horizontally?
I need:
Label Text
Label
TextArea
Here is my code. I've tried everything, including a labelField but the text does not appear in my view.
Ext.define('CAMSApp.view.OpBuyoffVoidView', {
extend: 'Ext.Panel',
alias: ['widget.opbuyoffvoidview'], //ToDo Use I18N
config: {
xtype: 'Ext.form.Panel',
cls: 'dialogview formview',
centered: true,
scrollable: 'vertical',
modal: true,
screenId: 'opbuyoffvoidview',
layout: {
type: 'vbox',
pack: 'start',
align: 'stretch',
},
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'Void Buyoff',
cls: 'grey-bold-34pt',
ui: 'transparent',
items: [{
xtype: 'button',
cls: 'grey-bold-40pt greyBtn',
text: 'Cancel',
idForAction: 'opbuyoff-void-cancel_btn',
}, {
xtype: 'spacer',
},{
xtype: 'button',
cls: 'grey-bold-40pt greyBtn',
text: 'Save',
idForAction: 'opbuyoff-void-save_btn',
}],
},
{
xtype: 'panel',
layout: {
type: 'vbox',
pack: 'start',
align: 'stretch',
padding: 5
},
items: [
{
xtype: 'label',
cls: 'block',
text: 'tesdfasrewaer'
},
{
fieldLabel: 'label',
labelWidth: 300,
xtype: 'textfield',
value: 'blahhhhh',
}, {
// xtype: 'panel' implied by default
xtype: 'textfield',
value: 'blahhhhhhhhhhh',
fieldLabel: 'text 2',
},{
xtype: 'textareafield',
width: 460,
height: 230,
idForUpdate: 'buyoff_reason_void',
//cls: 'priorityMedLabel',
}],
},
],
listeners: {
initialize: function(me, eOpts) {
CAMSApp.util.I18N.resolveStaticUIBindings(me);
},
show: function (me, eOpts) {
// Publish the screen id event.
log('[OpBuyoffVoid.show]');
CAMSApp.app.fireEvent('setscreenfocus', this);
},
},
}
});
So far I understood from your question that you need structure like below:
Label Text
Label
TextArea
Put below items in your view file:
items: [{
xtype: 'fieldset',
title: 'Enter your name and bio',
items: [{
xtype: 'textfield',
label: 'Name',
name: 'name'
}, {
xtype: 'textfield', // This textfield is dummy.
label: 'Bio', // You can simply put html here
labelWidth: '100%' // And can put your css to mimic default sencha label
}, {
xtype: 'textareafield',
name: 'bio'
}]
}]
Here is the fiddle for ref. Let me know if it serves your purpose or not.

Nested List view to show other

Here my code for showing list using sencha. When i click any any row how to make visible Detailed view.I have tried following link Sencha nested list way but no response.
List View
var tab= Ext.create('Ext.List', {
width: 320,
height: 320,
store: {
fields: ['ext_xtype','imgURL','arimg'],
data: [{
ext_xtype: 'Harry Potter 4',
imgURL:'bo.png',
arimg:'arrow.png'
},{
ext_xtype: 'Iphone5 64gb',
imgURL:'mo.png',
arimg:'arrow.png'
},{
ext_xtype: 'Hill Figure',
imgURL:'wa.png',
arimg:'arrow.png'
}]
},
itemTpl: '<img src="{imgURL}" width="35" heigh="35"></img><span>&nbsp&nbsp&nbsp{ext_xtype}<img src="{arimg}" width="25" height="25" align="right"></img>'
});
Detailed View
var sprfolievu = {
standardSubmit : false,
items: [{
xtype: 'fieldset',
title: '',
items: [
{
xtype: 'container',
layout: 'vbox',
title: '',
items: [{
xtype: 'container',
items: [{
xtype: 'container',
margin: 10,
layout: 'hbox',
items: [logo,{
xtype: 'label',
html: '&nbsp&nbsp&nbsp'
}
]
},]
},tablevuu ]
}
]
}]
}
Whats problem with my code?Please help me to sort it out
Your not following MVC, so code always looks ugly.
Learn about listeners and events
I have done some modification to sprfolievuand and added back button.
var sprfolievu = {
standardSubmit : false,
items: [{
xtype : 'toolbar',
items : [{
ui : 'back',
text : 'back',
handler : function(){
Ext.Viewport.setActiveItem(list);
}
}],
},{
xtype: 'fieldset',
title: '',
items: [{
xtype: 'container',
layout: 'vbox',
title: '',
items: [{
xtype: 'container',
items: [{
xtype: 'container',
margin: 10,
layout: 'hbox',
items: [{
xtype: 'label',
html: '&nbsp&nbsp&nbsp'
}]
}]
}]
}]
}]
};
Also done some changes in list.
var list = Ext.create('Ext.List', {
store: {
fields: ['ext_xtype','imgURL','arimg'],
data: [{
ext_xtype: 'Harry Potter 4',
imgURL:'bo.png',
arimg:'arrow.png'
},{
ext_xtype: 'Iphone5 64gb',
imgURL:'mo.png',
arimg:'arrow.png'
},{
ext_xtype: 'Hill Figure',
imgURL:'wa.png',
arimg:'arrow.png'
}]
},
itemTpl: ['<img src="{imgURL}" width="25" heigh="25">'+
'</img><span>{ext_xtype}</span>'+
'<img src="{arimg}" width="25" height="25" align="right"></img>'].join(),
listeners : {
itemtap: function(list, index, target, record, e, eOpts ) {
Ext.Viewport.setActiveItem(sprfolievu);
}
}
});
Ext.Viewport.add(list);
Ext.Viewport.add(sprfolievu);

Adding a toolbar to a grid - Extjs

I have the following grid here:
Ext.define('AM.view.user.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: 'All Users',
store: 'Users',
initComponent: function () {
this.columns = [{
header: 'Name',
dataIndex: 'name',
flex: 4
}, {
header: 'User ID',
dataIndex: 'user_id',
flex: 1
}, {
header: 'Address',
dataIndex: 'address',
flex: 3
}, {
header: 'Age',
dataIndex: 'agee',
flex: 5
}];
this.callParent(arguments);
}
});
Can a toolbar be added to the bottom of this grid or can they only be added to panels?
Also, how can I place normal text in a toolbar rather than a button?
Yes a grid panel inherits Ext.grid.Panel, you should be able to add:
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'button',
text: 'Left Button'
}, {
xtype: 'tbfill'
}, {
xtype: 'button',
text: 'Right Button'
}]
}]
Any component that has Docked layout can have toolbars docked. Since Ext.grid.Panel extends Ext.panel.Panel, you can dock to it. See the bbar config: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.panel.Panel-cfg-bbar
You can add text items to your toolbar by adding this to the toolbar's items:
{ xtype: 'tbtext', text: 'My Text' }
Docs for this here: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.toolbar.TextItem
Alternately you can also add button using 'bbar[...]' which is equivalent to
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [
{ xtype: 'button', text: 'Button 1' }
]
}]
this allows you to add buttons at the bottom of your gridpanel all other button properties are allowed to use.
sample code is here:
bbar: [
{ xtype: 'button', text: 'Button 1' },
{ xtype: 'button', text: 'Button 2' }
]
for more details you can refer the doc: http://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.panel.Panel-cfg-bbar

Resources