PDA

View Full Version : Scroll Event on Ext Component



anirbankundu
21 Jun 2012, 8:40 AM
Hello,

Let me tell you first I am very new to Ext4Js. I am using a Ext.Component as my west navigation. Inside that I have a custom tree and the tree loads data based on the dynamic scroll -i.e more the user scrolls down more items gets added to the tree. The tree is using knockout.js fundamentals. I need to get the scroll event of the Ext.Component - so that when the user scrolls down, the event gets fired.

The code I have is :



Ext.QuickTips.init();
var viewport = Ext.create('Ext.Viewport', {
id: 'border-example',
layout: 'border',
items: [
// create instance immediately
Ext.create('Ext.Component', {
region: 'north',
height: 60, // give north and south regions a height
contentEl: 'ui-layout-north'


}),
{
// lazily created panel (xtype:'panel' is default)
region: 'south',
contentEl: 'ui-layout-south',
split: true,
height: 100,
minSize: 100,
maxSize: 200,
collapsible: true,
collapsed: true,
title: 'South',
margins: '0 0 0 0'
},
{
region: 'west',
stateId: 'navigation-panel',
id: 'west-panel', // see Ext.getCmp() below
title: 'West',
split: true,
width: 200,
minWidth: 175,
maxWidth: 400,
collapsible: true,
animCollapse: true,
collapsed: true,
collapseMode: 'mini',
autoScroll: true,
margins: '0 0 0 5',
layout: 'accordion',
items: [{
contentEl: 'ui-layout-west',
title: 'Navigation',
autoScroll: true,
listeners: {
scroll: function (e, t, eOpts) {
Ext.Msg.alert('Scrolled !!!');
}
}

I don't know why the scroll event is not getting fired. Could anyone please guide.

Regards,
Anirban

grgur
21 Jun 2012, 11:09 AM
Change the listeners part to:



listeners: {
scroll: {
element: 'el',
fn: function(){ console.log('scrolling', arguments); }
}
}


Binding listeners is two-fold -> you either listen at the component level (component-related events, as in docs) or dom elements. We need the latter in this case, thus we bind the scroll event to the element, referenced by 'el'

Good luck :)

anirbankundu
21 Jun 2012, 2:58 PM
Thanks for your response. But this does not work. The Ext.Component is getting associated with the element "ui-layout-west"

I have 3 divs inside it. I have attached with all divs[just to see if the scroll gets fired or not] that are there, but still no scroll event gets fired.

items: [{
contentEl: 'ui-layout-west',
title: 'Navigation',
autoScroll: true,
listeners: {
scroll: {
element: 'ui-layout-west',
fn: function () { Ext.Msg.alert('Scrolled !!!');}
},
scroll: {
element: 'dmcontent',
fn: function () { Ext.Msg.alert('Scrolled !!!');}
},
scroll: {
element: 'DataManager',
fn: function () { Ext.Msg.alert('Scrolled !!!');}
}
}
}, {
title: 'Settings',
html: '<p>Some settings in here.</p>'
}, {
title: 'Information',
html: '<p>Some info in here.</p>'
}]

Thanks,
Anirban

grgur
21 Jun 2012, 9:22 PM
Try to use the exact code I posted, no need to change anything (even the 'el' string). I've tested and it works. Let me know either way :)

Animal
28 Oct 2012, 12:59 AM
advah, please do not hijack other people's threads. It makes answering difficult.

anirbankundu, the scroll listener you add will be added to the main element of the west component. Not the contentEl.

But I'm wondering why you are using contentEl.

You just have some static HTML in your page to display in every region? Doesn't seem much point in using ExtJS!

weizhang
2 Apr 2014, 9:46 PM
Thanks grgur. It works well.As soon as I moved the listener into controller it stopped working. Because scroll is not component related event is there a way to add dom event handler in controller?Thanks