PDA

View Full Version : Using a plugin in a plugin



grandanat
25 Feb 2010, 3:42 AM
I have a simple plugin for a combobox. I override some default properties for combo. Also i want to specify that my combos that are using this plugin to have a slider for their pagintoolbar. Here is it the code :



Ext.ns('Ext.ux.plugins');

Ext.ux.plugins.PagingCombobox = function(config) {
Ext.apply(this, config);
}

Ext.extend(Ext.ux.plugins.PagingCombobox, Ext.util.Observable, {

pagesize : 5,
minlistwidth : 360,

init : function(combo) {
combo.pageSize = this.pagesize;
combo.minListWidth = this.minlistwidth;
combo.plugins = new Ext.ux.SlidingPager();
this.combo = combo;
}

});


But my sliding bar doesn't appears. Where i'm doing wrong ?

Thanks

grandanat
25 Feb 2010, 3:50 AM
I tried also to declare slider plugin outside combo paging plugin, when using it but still doesn't work. Although i prefer to be encapsulated inside combo paging plugin.

pagingCombo = new Ext.ux.plugins.PagingCombobox({
plugins: new Ext.ux.SlidingPager()
});

...
xtype : 'combo',
plugins : pagingCombo

mschwartz
25 Feb 2010, 5:42 AM
You need to call the Ext.ux.SlidingPager' init function yourself. You can probably do it right away after instantiating it with new.

grandanat
26 Feb 2010, 3:05 AM
Realy bad code in my first post( i was overriding combo plugins :D)

OK. Let's start over.
I want to create a plugin for customizing a combobox.
My plugin should do :
1. set minListWidth
2. set pagesize dynamic (according to dropdown list view size), cos i don't want to have any scrollbars.
3. pagesize to use a slider (a pagingToolbar plugin)


1.done

2. For a normal list with a toolbar i add a listener for bodyresize event and i calculate pagesize according to list height. But in may combo plugin, in init method combo view is not yet initialized(combo view is initialized in initList). so i don't have dropdown list height

my fist question is when i can have access to dropdown list height ?

My first approach was to intercept expand event
in plugin init:

combo.on('expand', function() {
var contentHeight = ???;
var rowHeight = 36;
maxRowsPerGrid = Math.round(contentHeight / rowHeight);

this.store.baseParams = this.store.baseParams || {};
this.store.baseParams['limit'] = maxRowsPerGrid;

this.pageSize = maxRowsPerGrid;
this.store.reload({
params : {
start : 0
}
});

combo.pageSize = this.pageSize;
combo.pageTb.pageSize = this.pageSize;
});

At this point(after dropdown list is expanded , combo view is build, but still don't have, or don't know how to obtain view height



Ext.apply(combo, {
onRender : combo.onRender.createSequence(function(ct, position) {
if (this.view)
var as = this.view.height;
}),
initList : combo.initList.createSequence(function() {
Ext.apply(combo.view, {
onResize : combo.view.onResize.createSequence(function(adjWidth, adjHeight, rawWidth, rawHeight) {
if (this.view)
var as = this.view.height;
})
});
if (this.view)
var as = this.view.height;

combo.view.on('resize', function(width, size1, sz2, sz3, sz4) {
var contentHeight = ???;
var rowHeight = 36;
maxRowsPerGrid = Math.round(contentHeight / rowHeight);

this.store.baseParams = this.store.baseParams || {};
this.store.baseParams['limit'] = maxRowsPerGrid;

this.pageSize = maxRowsPerGrid;
this.store.reload({
params : {
start : 0
}
});

combo.pageSize = this.pageSize;
combo.pageTb.pageSize = this.pageSize;
});
})

// end of function onRender
});
,
As u can see i tried to call my method after view onresize or to intercept combo view resize event, but none of tries worked.


Do u have any advice ? maybe my approach isn't the right one.
Many thanks

grandanat
26 Feb 2010, 7:54 AM
After more digging in exj api code, i've found out that the only place where i can find height of combo dropdown list is dom element


var inner = combo.innerList.dom;
var h = Math.max(inner.clientHeight, inner.offsetHeight);


As i see, there are 2 aproaches:
- to intercept next event after combobox dropdown list is rendered, and get innerlist height then modify pagesize.
- or to intercept store loading(or pagesize) and there simply calculate pagesize(i have access to inner list height but i donw't know when).

i tried to put interceptor on combo.pageTb.getPageData, combo.pageTb.beforeLoad, combo.store.loadData, combo.store.loadRecords but none of there works.
at this moement innerlist is not rendered yet :(
So whatever i'd try seems that i cannot make a connection between the moment when pagesize is needed and the moment when innerlist is rendered :(

Do u have any advices ?