How to add swipe event to a container in sencha touch - extjs

I have a view of xtype container. If I swipe from left to right the view must change. It is more or less similar to carousel but I dont need carousel. I need to navigate between views with the help of swipe event.

listeners: {
painted:function(container) {
container.getContentEl().on('swipe',function() {
// your swipe code here
}
}
}

Related

Ionic2 - programmatically scroll an ion-scroll

I'm having a page with 2 scrollable views next to each other:
<ion-content>
<ion-scroll></ion-scroll>
<ion-scroll></ion-scroll>
</ion-content>
I want to programmatically scroll the first one, but it seems the scrollTo is only a method on ion-content (which I ofcourse can not scroll, I need to have the second one independant)
Is there any way to solve this?
update: added a plnkr to show what I need
If I am not mistaken you are trying to Scroll the Left Scroller and I see you have a view selector called leftCats.
So if you just change one line you will be able to scroll. Here is my code below:
NOTE: This is just plain javascript. It jumps to the scroll position. You can apply animation if you like later.
import {Component, ViewChild} from '#angular/core';
#Component({
templateUrl:"home.html"
})
export class HomePage implements AfterViewChecked {
#ViewChild('content') content;
#ViewChild('leftCats') leftItems;
constructor() {
}
scroll() {
//I want to scroll the left pane here
console.log('scroll');
this.leftItems.scrollElement.scrollTop += 50; // Change This Line
}
}
I have also forked it here: DEMO
Hope it helps.

updateLayout() causing parent container to scroll to top

calling updateLayout() is causing the parent container to "jump" to the top. Setting the viewconfig on the Ext.Container.container does not seem to help
viewConfig: {
preserveScrollOnRefresh: true
},
As suggested by Alexander, overriding beforeLayout and afterLayout for the parent container did the trick.
beforeLayout: function() {
var me = this,
scroller = me.getScrollable();
me.callParent(arguments);
if (scroller) {
me.savedScrollPos = scroller.getPosition();
}
},
afterLayout: function() {
var me = this,
scroller = me.getScrollable();
me.callParent(arguments);
if (scroller && me.savedScrollPos) {
scroller.scrollTo(me.savedScrollPos);
}
},
updateLayout is not the same as refresh, and preserveScrollOnRefresh only preserves scroll on refresh. You could look into ExtJS code how they did it (they don't really "preserve" scroll, they store the scroll position and scroll back to the correct position after refresh) and implement the same for updateLayout.
To cover more options for anyone having similar problems:
Changing the layout
As mentioned in question Avoid Ext.form validation scrolling to top, sometimes just changing the layout can do the trick.
For example form in ExtJS 4.x had anchor layout specified by default (ExtJS 6 has vbox), which caused the form to scroll to top on form field validation, if you change the layout to vbox, it does not scroll to top.
Suspending layout
If you have a component, that does not need to update the layout with its change, you can use the suspendLayout configuration.

Extjs mouseover and click event not working together for an element id

I have a button and in my controller i created one mouse over event and a click event for that button's id. But everytime when i click button it goes to the mouseover event function only, but when I comment the mouseover it goes to the click event function nicely. Why this is so? I am using ext4.1
thanks in advance.
me.control({
'#notificationIconId':{
click:me.notificationClick
},
'#notificationIconId':{
mouseover:me.notificationMouseOver
}
});
},
notificationMouseOver : function (){
alert('1')
},
notificationClick :function(menuitem)
{
alert('2')
}
You're using two times the same key '#notificationIconId' in a Javascript object... So, the last one is overriding previous ones.
You can add multiple listeners for the same selector:
'#notificationIconId': {
click: me.notificationClick
,mouseover: me.notificationMouseOver
}

ExtJS MVC Controller ref to Tab Panel's active tab

I have an MVC app which has a Tab Panel rendered as the only item in the viewport. Within the tabs I would like to put the same type of component, for which the event handling is equal within all tabs.
Therefore I need an ExtJS MVC Controller ref to the active tab, that would lead me to execute events on the components in the active tab. Is it possible to have such a ref?
My current approach is this:
get reference to Tab Panel
call getActiveTab()
call the controller events for the component in active tab
Is it possible to encapsulate the above 3 steps in one controller ref? Would be beautiful :-)
I'm using ExtJS 4.1.
Personally, I think controller refs are overrated. This sounds like a simple case where you can use one as you describe, but I prefer to listen to the event, and navigate from the firing component to the one I need.
In your case, assuming your tab panel contains regular ext panels, I'd do something like the following:
onButtonClick: function (button) {
var panel = button.up('panel[tab]');
if (panel) {
panel.someMethod();
}
}
The up method will find the closest ancestor that is of xtype panel and has a property named tab. If you have more specific xtypes or known properties, use those instead.
The panel should be the active one (else how was its button clicked?) but you can check that by going up another level to the tab panel and getting the activeTab there.
onButtonClick: function (button) {
var panel = button.up('panel[tab]'),
tabPanel = button.up('tabpanel'),
activeTab = tabPanel && tabPanel.getActiveTab();
if (panel && panel === activeTab) {
panel.someMethod();
}
}
Say your tabPanel has itemId: 'content'. Inside that panel you will have bunch of tabs and on each tab you will have bunch of buttons (as an example). And you want to handle all these button's click in one controller. Do I understand you correctly?
I believe that simple ref inside your controller would work:
this.control('#content button', {
click: this.buttonClicked
}
});

Ext js - Dynamically changing content of Tab in a TabPanel

I have an (Ext JS) tab panel where the hidden tabs aren't loaded at all upon initial instantiation, (the only thing I set is the title).
Upon 'activation' of a tab I want to call a method , which then instanstiates a new FormPanel/GridPanel and put this content into the tab.
Can someone point me to a code example or give me tips on how to do this??
Thanks so much!
Just build a new panel and add it to the activated tab. Then call doLayout().
listeners: {
activate: function(panel) {
var formPanel = ....
panel.add(formPanel);
panel.doLayout();
}
}

Resources