add element to carousel sencha - add

In sencha touch, I have a carousel declared like this:
ajaxNav = new Ext.Panel({
scroll: 'vertical',
cls: 'card1 demo-data',
styleHtmlContent: true,
layout: {
type: 'vbox',
align: 'stretch'
},
defaults: {
flex: 1
},
items: [{
xtype: 'carousel',
items: [{
id:'tab-1',
html: '',
cls: 'card card1'
},
{
id:'tab-2',
html: '<p>Clicking on either side of the indicators below</p>',
cls: 'card card2'
},
{
id:'tab-3',
html: 'Card #3',
cls: 'card card3'
}]
}]
});
Does anybody knows how to add elements dinamycally??

I write you a simple example to show you how to dinamically add a new panel to an existing Ext.Carousel element.
Ext.setup({
onReady: function() {
var ajaxNav = new Ext.Carousel({
fullscreen: true,
dockedItems: {
xtype: 'toolbar',
title: 'Demo',
items: [{
xtype: 'button',
ui: 'action',
text: 'Add',
handler: function(){
var element = new Ext.Panel({
html: 'New Element'
});
ajaxNav.add(element);
ajaxNav.doLayout();
}
}]
},
items: [{
id:'tab-1',
html: '',
cls: 'card card1'
},{
id:'tab-2',
html: '<p>Clicking on either side of the indicators below</p>',
cls: 'card card2'
},{
id:'tab-3',
html: 'Card #3',
cls: 'card card3'
}]
});
}
});
As you can see, on the "Add" press button event, you first have to define your panel according to your needs, then add it to your carousel, and, the most important thing, you have to let the carousel recalculate his layout calling the "doLayout()" function.
Hope this helps.

Related

Extjs child item not filling the parent container

My problem is, even if I used "layout: 'fit'" in all my children items within a boarder layout, they just shrinks into a small box rather than fill the parent, as described in fit layout.
I want the EDS.view.selector.Container to fill the "navigation" section of my boarder layout.
(Code excerpt)
Ext.define('EDS.view.selector.Container', {
extend: 'Ext.panel.Panel',
alias : 'widget.selectorcontainer',
layout: 'fit',
initComponent: function(){
this.items = [
{
xtype: 'tabpanel',
defaults: {
bodyPadding: 10
},
layout: 'fit',
items:[
{
title: 'Organization',
id: 'selector-organization',
tag: 'div',
html: 'div here',
height: '100%',
}
]
}
],
this.callParent();
},
});
(Controller)
init: function(){
console.log('controller.init()');
new Ext.Viewport({
title: 'Data Analysis',
layout: 'border',
defaults: {
collapsible: true,
split: true,
bodyStyle: 'padding: 15px',
},
items: [{
title: 'Navigation',
region:'west',
margins: '5 0 0 0',
cmargins: '5 5 0 0',
width: 600,
minSize: 100,
maxSize: 250,
items: [
{
id: 'selector-container',
xtype: 'selectorcontainer',
layout: 'fit',
}
]
},{
title: 'Main Content',
collapsible: false,
region:'center',
margins: '5 0 0 0'
}]
});
}
You did not set up layout for wrapper containers in your border layout:
items: [{
title: 'Navigation',
region:'west',
layout: 'fit',
...
items: [
]
},{
title: 'Main Content',
collapsible: false,
region:'center',
layout: 'fit',
...
}]
Remember: In ExtJS any plain JS object that goes into items property of a container will be converted into some type of Ext component with xtype defined by defaultType property of that container. In most cases it will be panel.

Dynamically Building a Container with this.setItems()

I'm trying to build my container in the initialize() function by creating all my components then calling this.setItems([...]). For some reason, my components are being placed on top of each other, rather than after each other in the vbox.
I am able to grab the top component and move it down, as is shown in the attached image.
Simplified view with two components:
Ext.define("Sencha.view.DynamicView", {
extend: 'Ext.Container',
xtype: 'dynamic-view',
requires: [],
config: {
layout: {
type: 'vbox'
},
flex: 1,
cls: 'view-container',
store: null
},
createRadioSet: function() {
this.radioFieldSet = Ext.create('Ext.form.FormPanel', {
flex: 1,
items: [{
xtype: 'fieldset',
title: 'About You',
defaults: {
xtype: 'radiofield',
labelWidth: '40%'
},
instructions: 'Favorite color?',
items: [{
name: 'color',
value: 'red',
label: 'Red'
},
{
name: 'color',
value: 'green',
label: 'Green'
}
]
}]
});
return this.radioFieldSet;
},
createCheckboxSet: function() {
this.checkboxFieldSet = Ext.create('Ext.form.FormPanel', {
flex: 1,
items: [{
xtype: 'fieldset',
title: 'Check all that apply',
defaults: {
xtype: 'checkboxfield',
labelWidth: '40%'
},
instructions: 'Tell us all about yourself',
items: [{
name: 'firstName',
value: 'First',
label: 'First Name'
},
{
name: 'lastName',
value: 'Last',
label: 'Last Name'
}
]
}]
});
return this.checkboxFieldSet;
},
initialize: function() {
this.callParent(arguments); // #TDeBailleul - fixed
var r1 = this.createRadioSet();
var cbSet1 = this.createCheckboxSet();
// this.add(cbSet1);
// this.add(r1);
this.setItems([r1, cbSet1]);
}
});
My problem was that I was adding my components incorrectly in a tab controller. I'm including an example that creates buttons on one tab and the checkboxes on another tab.
Ext.Loader.setConfig({
enabled : true
});
Ext.application({
name : ('SF' || 'SenchaFiddle'),
createRadioSet: function () {
this.radioFieldSet = Ext.create('Ext.form.FormPanel', {
height: '300px',
width: '300px',
items: [
{
xtype: 'fieldset',
title: 'Title',
defaults: {
xtype: 'radiofield',
labelWidth: '40%'
},
instructions: 'Favorite color?',
items: [
{
name: 'color',
value: 'red',
label: 'Red'
},
{
name: 'color',
value: 'green',
label: 'Green'
}
]
}
]
});
return this.radioFieldSet;
},
createButton: function(i) {
return Ext.create('Ext.Button', {
text: 'hello' + i,
height: '50px',
width: '100px'
});
},
launch: function () {
var tabPanel = Ext.create('Ext.tab.Panel', {
layout: 'card',
padding: 2,
tabBarPosition: 'bottom',
items: [
{
id: 'tab1',
title: 'Home',
layout: 'hbox',
xtype: 'container',
iconCls: 'home'
},
{
id: 'tab2',
title: 'More',
layout: 'hbox',
xtype: 'container',
iconCls: 'star'
}
]
});
Ext.Viewport.add(tabPanel);
var a,b;
for (var i = 0; i < 3; i++) {
a = this.createButton(i);
b = this.createRadioSet();
// tabPanel.getAt(0).add(b); // Reference the proper component: Tab 1
Ext.getCmp('tab1').add(a);
Ext.getCmp('tab2').add(b);
}
}
});

Sencha Touch 1.x, how to create a container with two components using hbox

I have a set of data in my dataStore, and I output my data using textfields within containers in a .js view. I also disabled the fields only to show data and be uneditable. I was wondering if there are any alternatives to using 'xtype: textfield', and 'xtype: textareafield' ?
With this question entailed, I'm trying to create a container with two components using hbox as such an alternative, and this is the code that I have of the following:
var formContainer1 = new Ext.Container({
width: '100%',
height: '65%',
layout: {
type: 'vbox',
// type: 'hbox',
align: 'stretch',
},
defaults: {
labelAlign:'left',
// labelWidth:'30%',
labelWidth:'25%',
},
items: [
{
bodyStyle: "background-color: #52ABD5;", //Color = Light Blue
html: '<font face="Helvetica" size="4" color="white" ><p>Information</p>'
},
{
xtype: 'textfield',
// xtype: 'component',
name: 'Description',
disabled: true,
label: 'Desc',
},{
xtype: 'textfield',
// xtype: 'component',
name: 'Number',
disabled: true,
label: 'ANumber',
id: 'ANumber',
},{
xtype: 'textareafield',
// xtype: 'component',
name: 'directions',
disabled: true,
label: 'Directions',
height: 'auto',
// defaults: {
//required: true,
// labelAlign: 'left',
// labelWidth: '100%'
// },
},
],
/* dockedItems: [
{
layout: 'hbox',
xtype: 'toolbar',
dock: 'top',
title: 'Information',
// scroll: 'horizontal',
}
]*/
});
Now this code works just fine, except i don't want to use 'textfield' or 'textareafield'. I'm still using those because I tried using xtype: component, but it didn't work. Also when I tried this in hbox layout, it didn't show up like I wanted it to (row after row). I'm pretty sure I'm just not understanding the "components using hbox" part because yeah I want this container to look really close to this:
Img url: http://farm3.staticflickr.com/2683/5852914556_b2886e3363.jpg
(note: referring to the right most iphone picture w/ the containers)
Please clarify for me on the "w/ 2 components usnig hbox" part. Thanks!
By the way: http://www.sencha.com/forum/showthread.php?186243-Alternatives-to-textfield&p=759843#post759843
My username on that post: kevinjset. This was the original post that I posted on Sencha touch forums asking the same question, I just wanted to see if you guys on Stack Overflow! can help me out too! Thanks, appeciated.
This is fairly tedious but it might help you out
{
xtype:'fieldset',
title:'fieldset1',
items:[{
xtype:'container',
layout:'hbox',
items:[{
xtype:'container',
flex:1,
html:'1'
},{
xtype:'container',
flex:1,
html:'2'
},{
xtype:'container',
flex:1,
html:'3'
}]
},{
xtype:'container',
layout:'hbox',
items:[{
xtype:'container',
flex:1,
html:'4'
},{
xtype:'container',
flex:1,
html:'4'
},{
xtype:'container',
flex:1,
html:'6'
}]
}]
}

As a "target" handler toolbar button, the method of the controller?

Hello!
I want this handler "handler: onEventControler (???)" removed from view (it do not belong there)
For grid view set dockedItems this cod:
this.dockedItems = [{
xtype: 'toolbar',
items: [{
xtype: 'newstation'
},{
id: 'add-persone-btn',
xtype: 'button',
itemId: 'add',
text: 'Add',
iconCls: 'icon-add',
handler: onEventControler(???)
}, '-', {
itemId: 'delete',
text: 'Delete',
iconCls: 'icon-delete',
disabled: true,
handler: function(){
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
}
}]
}]
I also tried to implement a this.control, but I could not ask for a button selectorQuery.
How do I properly respecting the architecture mvc extJs4?
thank you.
You should be able to do something like this inside the controller of this view.
init: function () {
this.control({
'toolbar #add': {
click: this.onAddStation
}
});
}
Handler:
onAddStation: function(button, e, eOpts){
//Handle
}
Alternatively, you could use an "action" config on your button.
action: 'addstation'
Then you could have:
init: function () {
this.control({
'button[action=addstation]': {
click: me.onAddStation
}
});
}
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.button.Button
This is method "initComponent" for view gridd view:
initComponent: function () {
this.plugins = [Ext.create('Ext.grid.plugin.RowEditing')];
this.dockedItems = [{
xtype: 'toolbar',
items: [{
xtype: 'button',
itemId: 'add',
text: 'Add',
iconCls: 'icon-add',
action: 'add-new-persone'
}, '-', {
itemId: 'delete',
text: 'Delete',
iconCls: 'icon-delete',
action: 'delete-persone',
disabled: true
}, '-', {
itemId: 'synch',
text: 'Synchronization',
iconCls: 'icon-synch',
action: 'synch-persone'
}]
}];
// paging bar on the bottom
this.bbar = Ext.create('Ext.PagingToolbar', {
store: this.store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display",
items:[]
});
this._initColumns();
this._initFilter();
this.callParent(arguments);
},

Sencha touch panel layout not taking up all available screenspace

I have a panel which is fullscreen;
PortalDashboard.views.Dashboardcard = Ext.extend(Ext.Panel, {
fullscreen: true,
title: 'Dashboard',
html: '',
cls: 'card5',
iconCls: 'team',
layout: Ext.Viewport.orientation == 'landscape' ? {
type: 'hbox',
pack: 'center',
align: 'stretch'
} : {
type: 'vbox',
align: 'stretch',
pack: 'center'
},
monitorOrientation: true,
listeners: {
orientationchange : this.onOrientationChange,
},
styleHtmlContent: false,
initComponent: function () {
Ext.apply(this, {
items: [
{
xtype: 'dashboardbox',
items: [rep1, rep2, rep3]
}, {
xtype: 'dashboardbox',
items: [rep4, rep5, rep6]
}]
});
PortalDashboard.views.Dashboardcard.superclass.initComponent.apply(this, arguments);
}
})
So the panel has a hbox layout with 2 child panels. The child panels actually take up the full amount of horizontal space, but not vertically.
I can set the min-height in the css, which gets respected on in chrome and safari on my pc... but the ipad ignores it.
The child panels are defined as;
PortalDashboard.views.DashboxBox = Ext.extend(Ext.Panel, {
cls: 'dashbox',
monitorOrientation: true,
listeners: {
orientationchange : this.onOrientationChange,
},
layout: Ext.Viewport.orientation == 'landscape' ? {
type: 'vbox',
align: 'stretch',
pack: 'center'
} : {
type: 'hbox',
align: 'stretch',
pack: 'center'
},
defaults: {
flex: 1
}
});
Ext.reg('dashboardbox', PortalDashboard.views.DashboxBox);
I've had this before with a TabPanel parent of some sub panels. Try layout: 'fit' in your parent panel. (Although I'm not sure if adding it to your current list of layout options will work or if it needs to be set by itself.)

Resources