Sencha Touch Carousel Not Visible - javascript

I'm attempting to render a simple carousel in Sencha Touch, however, it's not showing up. The only thing I see are the indicator dots for the items. Inspecting in Chrome shows that the tags are being added, but I can't see them.
Carousel View:
Ext.define('Project.view.ChartCarousel', {
extend : 'Ext.Carousel',
xtype : 'chartCarousel',
config : {
title : 'Title',
fullscreen: 'true',
width: '100',
height: '100',
jumpToIndex: 0,
defaults : {
padding: '10 10 10 10'
},
items : [{
html:'<div style="text-align:center">test 1</div>'
}, {
html:'<div style="text-align:center">test 2</div>'
}, {
html:'<div style="text-align:center">test 3</div>'
}]
}
});
Containing View:
Ext.define('Project.view.SummaryChart',{
extend: 'Ext.form.Panel',
xtype: 'summaryChart',
requires: [
'Ext.Toolbar'
],
config: {
items: [
{
xtype: 'chartCarousel'
}
]
},
initialize: function() {
this.callParent(arguments);
}
});

I found the answer. I needed to add flex: '1' to the carousel's config.

Related

ExtJS MVC adding a toolbar

I have the following situation, I am trying to add a toolbar (Ext.toolbar.Toolbar) to a grid (Ext.panel.grid). The grid is inside of a Ext.window.Window which is in my main app.js looking something like this:
Ext.application({
name: 'FileBrowser',
appFolder: '/Scripts/dashboard/FileBrowserApp',
controllers:['BrowserController'],
launch: function() {
win = Ext.create('Ext.window.Window', {
title: 'Document Library',
width: 700,
height: 500,
layout: 'border',
bodyStyle: 'padding: 5px;',
items: [
{
xtype:'tree_dir'
},
{
xtype:'grid_file',
}
]
});
win.show();
}
})
My question is, how do I do that? Do I dynamically add the toolbar in the controller? If so how do I access the above grid_file from the controller? Should I somehow add it inside my grid_file view? Then how do I access the toolbar view?
myPanel.addDocked({
xtype: 'toolbar',
dock: 'top',
items:[
{
xtype:'button',text:'Open Win1',ref:'win1Button'
},{
xtype:'button',text:'Open Win2',ref:'win2Button'
}]
});

Editor cannot disappear after closing Window

I got a problem on Ext 4.1.0 and Ext 4.1.1
Double click first cell to edit it and then click window close button, the editor still floats on the page.But it is ok for last cell.
Anyone met this problem before? Thanks
Ext.onReady(function(){
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'Lisa', "email":"lisa#simpsons.com", "phone":"1224" },
{ 'name': 'Bart', "email":"bart#simpsons.com", "phone":"1234" },
{ 'name': 'Homer', "email":"home#simpsons.com", "phone":"1244" },
{ 'name': 'Marge', "email":"marge#simpsons.com", "phone":"1254" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
var table = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{
text: 'Name',
dataIndex: 'name',
editor: { xtype: 'textfield', toFrontOnShow: false }
},
{
text: 'Email',
dataIndex: 'email',
flex: 1
},
{
text: 'Phone',
dataIndex: 'phone',
editor: {
xtype: 'numberfield',
hideTrigger: true,
validateOnChange : false
}
}
],
height: 200,
width: 400,
plugins:[ Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})]
});
var window = new Ext.Window({
id: 'abc',
title :'abc',
modal : true,
layout: 'border',
resizable : true,
draggable : true,
closable : true,
closeAction : 'hide',
width :410,
height :210,
items : [table]
});
window.show();
});
The easiest way to handle this for you, would be to listen to the window's beforeclose event and cancel any editing in this event using the celleditor's cancelEdit method as described here in the docs.
For example, here is your window object (from your code above) with the listener applied:
var window = new Ext.Window({
id: 'abc',
title :'abc',
modal : true,
layout: 'border',
resizable : true,
draggable : true,
closable : true,
closeAction : 'hide',
width :410,
height :210,
items : [ table],
// add this listener to your window
listeners: {
beforeclose: function(panel) {
var view = panel.down('gridview');
if (view && view.editingPlugin) {
view.editingPlugin.cancelEdit();
}
}
}
});
Reply to comment:
Here's an override that would do the same thing. You would have to include this override in each app after ExtJS initialization though.
Of course it is also possible to replace the init function in the Ext.grid.plugin.Editor source code with this one (then you wouldn't have to include the override in the app) but I wouldn't recommend doing that for a number of reasons.
Ext.override(Ext.grid.plugin.Editor, {
init: function(grid) {
// the normal init code (below) must be included in the override
var me = this;
me.grid = grid;
me.view = grid.view;
me.initEvents();
me.mon(grid, 'reconfigure', me.onReconfigure, me);
me.onReconfigure();
grid.relayEvents(me, [
'beforeedit',
'edit',
'validateedit',
'canceledit'
]);
grid.isEditable = true;
grid.editingPlugin = grid.view.editingPlugin = me;
// additional code to cancel editing before a grid is hidden
grid.on('beforehide', function(grid) {
var view = grid.view;
if (view && view.editingPlugin) {
view.editingPlugin.cancelEdit();
}
});
// additional code to cancel editing before a grid is destroyed
grid.on('beforedestroy', function(grid) {
var view = grid.view;
if (view && view.editingPlugin) {
view.editingPlugin.cancelEdit();
}
});
}
});
I would also recommend looking into MVC architecture, it would make handling things like this alot easier for you.

Sencha Touch 2 panel not stretching to full height

I have made this application in sencha touch 2
Ext.application({
name: "SOMENAME",
launch: function () {
//Ext.Viewport.setLayout({type:'fit',align:'stretch'});
var mainPanel = Ext.create('Ext.Container', {
layout: 'vbox',
items: [
{
xtype: 'panel',
layout: {
type: 'card',
animation: 'slide'
},
height: 300,
id: 'nooPanel',
items: [
{
html: 'Page 1'
},
{
html: 'Page 2 asdasdasd'
},
{
html: 'Page 3 asdq323434'
}
]
},
{
xtype: 'button',
text: 'Next',
handler: function (button, e, eOpts) {
var panel = Ext.getCmp('nooPanel');
var totalItems = panel.getInnerItems().length;
var index = panel.getInnerItems().indexOf(panel.getActiveItem());
panel.setActiveItem((index + 1) % totalItems);
}
}
]
});
Ext.Viewport.add(mainPanel);
mainPanel.down('panel').setActiveItem(0);
},
init: function () {
}
})
but the problem is that if i dont put the height to 300 on the panel of which the layout is card its height becomes 0 and nothing is displayed
even after setting layout to fit on the viewport what should i do?
When you put items into a container with layout: 'vbox', Sencha Touch 2 needs to know what is the height ratio between these child items.
If you want to has a full-height items inside a vbox, add this config to that item, instead of height: 300, use flex:1
well digging into the configs i found out flex as a part of config..
through this property i can define the ratios of all the elements inside a container having vbox layout
so if i set the flex to 3 different items as 10,1,1 then the first one will take up (10/(10+1+1))*100 % of the space..
kind of worked for me..
but still looking for the final ans
You can only have one item in a container when you use 'fit'. I added a couple of 'flex:' values to give what I think you want. Here is the code and it's on SenchaFiddle for testing.
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
name: "SOMENAME",
launch: function () {
//Ext.Viewport.setLayout({type:'fit',align:'stretch'});
var mainPanel = Ext.create('Ext.Container', {
layout: 'vbox',
items: [
{
xtype: 'panel',
flex: 20,
layout: {
type: 'card',
animation: 'slide'
},
//height:300,
id: 'nooPanel',
items: [
{
html: 'Page 1',
flex:1
},
{
html: 'Page 2 asdasdasd'
},
{
html: 'Page 3 asdq323434'
}
]
},
{
xtype: 'button',
text: 'Next',
flex: 1,
handler: function (button, e, eOpts) {
var panel = Ext.getCmp('nooPanel');
var totalItems = panel.getInnerItems().length;
var index = panel.getInnerItems().indexOf(panel.getActiveItem());
panel.setActiveItem((index + 1) % totalItems);
}
}
]
});
Ext.Viewport.add(mainPanel);
mainPanel.down('panel').setActiveItem(0);
},
init: function () {
}
})

Sencha static top and bottom bars for page changes

I've been learning sencha touch 2.0 over the last 2 weeks and i've stumbled onto two problems. What i would like to do is have a static top bar and bottom bar on my page and let the dynamic content be controlled by buttons placed at the bottom dock. I've spent 4 hours on trying to get this to work the way i want to, i'm almost there but i need a little guidance.
My first problem is that i want to add an image to the static top dock. The code that was suggested in another form does not work.
var topBar = new Ext.BoxComponent(
{
xtype: 'box',
autoEl: {tag: 'img', src:'/resources/icons/icon.png'}
}
)
This code doesnt give any errors but it also doesnt show the required image. The image is 60px by 30px
The second problem i'm having is that i would like to add icons to my bottom dock so that when the user click on them, the page would change to show a new page. I have a form with 3 fields that i would like to link to one of the icons on the bottom dock so when the icon is clicked, the form would show. Here is the full code:
Ext.setup({
phoneStartupScreen : 'resources/images/icon.png',
icon : 'resources/images/Homescreen.png',
glossOnIcon : false,
onReady : function() {
var topBar = new Ext.BoxComponent(
{
xtype: 'box',
autoEl: {tag: 'img', src:'/resources/icons/icon.png'}
}
)
var tapHandler = function (btn, evt) {
alert("Button '" + btn.text + "' tapped.");
}
var form = new Ext.form.FormPanel({
items:
[
{
xtype: "textfield",
name: "name",
label: "Name",
placeHolder: "your name here"
},
{
xtype: "emailfield",
name: "email",
label: "Email",
placeHolder: "you#example.com"
},
{
xtype: "urlfield",
name: "url",
label: "Url",
placeHolder: "http://www.example.com"
}
]
})
var searchPageContent ={
html:'This is a test for search page'
}
var userPageContent ={
html:'This is a test for user page'
}
var dockedItems = [
{
xtype : 'toolbar',
dock : 'top',
items : topBar
},
{
xtype: "toolbar",
dock: "bottom",
items: [
{
xtype: 'spacer'
},
{
iconMask: true,
iconCls: "favorites",
items: form
},
{
xtype: 'spacer'
},
{
iconMask: true,
iconCls: "search",
items: searchPageContent
},
{
xtype: 'spacer'
},
{
iconMask: true,
iconCls: "user",
items: userPageContent
},
{
xtype: 'spacer'
},
]
}
]
new Ext.Panel({
id : 'buttonsPanel',
fullscreen : true,
dockedItems : dockedItems
});
}
});
as mentioned before, i have been able to create the static top and bottom bars but my image does not work in my top bar, which is my first problem, and when i click one of the 3 buttons, nothing happens; i would like my form to be displayed when i click my favorites button but nothing happens. Where have i gone wrong?
Thank you
After a few days of wrestling with sencha, i found an example that almost had what i wanted so modified it and it worked out exactly the way i wanted. I now have a static top bar and a static bottom bar with page icons such that when i click the page icons, the main content scrolls and the new page is displayed.
Ext.setup({
onReady: function() {
var topBar = new Ext.BoxComponent({
layout: 'hbox',
html:
'<img src="resources/icons/icon.png" height="30", width="48"/>',
flex: 1,
style:{
textAlign: 'center'
}
})
var dockedItems = [
{
//this creates the top bar, places it at the top of the page and gives it a background image
xtype : 'toolbar',
dock : 'top',
style: 'background-image:url("resources/images/backgroundSmall.png"); background-repeat: repeat-x;',
items : topBar
}
]
// Sub-page sections
// Main portion of the page, which includes top toolbar and content
var welcome = new Ext.Panel({
items: [{
html: 'this is the welcome screen'
}],
title: "Welcome",
iconCls: "welcome",
});
var search = new Ext.Panel({
items: [{
html: 'this is the search screen'
}],
title: "Search",
iconCls: "search",
});
// This is the outer panel with the bottom toolbar
var wrapper = new Ext.TabPanel({
fullscreen: true,
tabBar: {
dock: 'bottom',
style: 'background:#8a9cB2;',
layout: {
pack: 'center'
}
},
items: [
welcome,
search,
{
iconMask: true,
iconCls: "search"
},
{
iconMask: true,
iconCls: "user"
}
],
dockedItems: dockedItems
});
}
});

How to completely hide the dockedItems toolbar

I'm able to hide items among the dockedItems of a TabPanel, but am wanting to temporarily hide the entire dock, because the toolbar itself still takes up space and the rest of the content does not fill the screen.
So far, I do like so:
myApp.views.productList.dockedItems.items[0].removeAll(true);
myApp.views.productList.doComponentLayout();
Alternatively:
myApp.views.productList.getComponent('search').removeAll(true);
myApp.views.productList.doComponentLayout();
But neither removes the dockedItems toolbar itself.
I've even tried to give the dockedItems individually and collectively an id: to remove the whole component, but without luck. I've also tried moving the toolbar in question out from the docked items and into the items: property of the containing panel, but this breaks other things in my app that I'd rather not change at present.
Any clues on how to do this?
If I understand you correctly you want to temporally remove tabBar from a tabPanel. I was able to accomplish this through giving and id to my tabBar and then using removeDocked and addDocked methods. I'm new to sencha-touch so most likely there is a better way of doing this
The code below removes tabBar from tabPanel and then adds it back again.
Ext.setup({
onReady: function() {
var tabpanel = new Ext.TabPanel({
ui : 'dark',
sortable : true,
tabBar:{
id: 'tabPanelTabBar'
},
items: [
{title: 'Tab 1',html : '1',cls : 'card1'},
{title: 'Tab 2',html : '2',cls : 'card2'},
{title: 'Tab 3',html : '3',cls : 'card3'}
]
});
var paneltest = new Ext.Panel({
fullscreen: true,
dockedItems:[
{
xtype: 'button',
text: 'Disable TabBar',
scope: this,
hasDisabled: false,
handler: function(btn) {
console.log(btn);
if (btn.hasDisabled) {
tabpanel.addDocked(Ext.getCmp('tabPanelTabBar'), 0);
btn.hasDisabled = false;
btn.setText('Disable TabBar');
} else {
tabpanel.removeDocked(Ext.getCmp('tabPanelTabBar'), false)
btn.hasDisabled = true;
btn.setText('Enable TabBar');
}
}}
],
items:[tabpanel]
});
paneltest.show()
}
})
в dockedItems добавить button, которая будет обращаться к элементу panel.dockedItems и изменять/скрывать сам dockedItems
function f_create_accord(P_el_id, P_el_params) {
P_el = Ext.create
(
'Ext.panel.Panel',
{
id: P_el_id
, border: false
, x: P_el_params.left
, y: P_el_params.top
, id_el: P_el_params.id_el
, layout: 'accordion'
, dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [{
P_el_id: P_el_id,
xtype: 'button',
text: 'добавить',
}, {
id_el: P_el_id,
xtype: 'button',
text: 'скрыть',
vision: true,
listeners: {
click: function (el, v2, v3) {
if (el.vision) {
Ext.getCmp(el.id_el).dockedItems.items[0].setHeight(5);
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[0].hide();
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[1].setWidth(Ext.getCmp(el.id_el).getWidth());
el.vision = false
}
else {
Ext.getCmp(el.id_el).dockedItems.items[0].setHeight('15px');
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[0].show();
Ext.getCmp(el.id_el).dockedItems.items[0].items.items[1].setWidth(60);
el.vision = true
}
// Ext.getCmp(el.id_el).dockedItems.items[i].hide();
}
}
}]
}]
}
);
P_el.setStyle('position', 'absolute');
P_el.setStyle('box-shadow', ' 0px 0px 0px 1px green');
P_el.setStyle('background', 'border-box');
return P_el;
}

Categories