PDA

View Full Version : PageSize plugin for PagingToolbar



rubensr
4 Oct 2007, 8:48 PM
Hi All,

Just created my first (quite simple) extension - actually a plugin for PagingToolbar that allows you to change the pageSize property using a combo box with some predefined options. This was developed using Ext 2.0a - I'm interested in comments on how this
could have been done more efficiently, etc. Thanks in advance.



Ext.namespace('Ext.ux');

Ext.ux.PageSizePlugin = function() {
PageSizePlugin.superclass.constructor.call(this, {
store: new Ext.data.SimpleStore({
fields: ['text', 'value'],
data: [['10', 10], ['20', 20], ['30', 30], ['50', 50], ['100', 100]]
}),
mode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
allowBlank: false,
triggerAction: 'all',
width: 40
});
};

Ext.extend(Ext.ux.PageSizePlugin, Ext.form.ComboBox, {
init: function(paging) {
paging.on('render', this.onInitView, this);
},

onInitView: function(paging) {
paging.add('-',
this,
'Items per page'
);
this.setValue(paging.pageSize);
this.on('select', this.onPageSizeChanged, paging);
},

onPageSizeChanged: function(combo) {
this.pageSize = parseInt(combo.getValue());
this.doLoad(0);
}
});


Hope this is useful to someone.

6epcepk
4 Oct 2007, 9:06 PM
Thanks for extension!

reang
4 Oct 2007, 11:48 PM
would you please tell me how to apply this plugin on grid.

galdaka
5 Oct 2007, 12:21 AM
Thanks!! Good work!!

rubensr
5 Oct 2007, 4:15 AM
Reang,

To use the plugin, you need to add it to the PagingToolbar creation:



var myPagingToolbar = new Ext.PagingToolbar({
displayInfo: true,
emptyMsg: 'Nothing to show',
store: this.store,
plugins: [new Ext.ux.PageSizePlugin()]
});


and then just add it to the 'bbar' config option of the grid.

cuonglb
9 Oct 2007, 3:23 AM
Nice plugin ! =D>

hubo1505
10 Oct 2007, 5:58 PM
good job!

jo2008
12 Oct 2007, 2:16 AM
I had a problem with your code. Got an error that "PageSizePlugin" was not found. I added the red code shown below and it worked perfectly ever since.


Ext.ux.PageSizePlugin = function() {
Ext.ux.PageSizePlugin.superclass.constructor.call(this, {
.....


Thanks!

attiato
12 Oct 2007, 8:04 AM
how do i change the width of the combobox in an instance?

rubensr
14 Oct 2007, 6:01 PM
Attiato,

You can change that by changing the "width" config parameter of the superclass constructor call (in the code I posted, it is '40') or you can pass that through a config parameter in the class initialization (which I haven't done in my example).

Hope this helps
Rubens

attiato
15 Oct 2007, 4:27 AM
Another question!
how do i get the curent page size into a variable that i can use later?

rubensr
16 Oct 2007, 5:55 PM
The page size is a member of the paging toolbar, you can see how I use it in the code in the line:



...
this.setValue(paging.pageSize);
...


So, to access the page size, just use the pageSize property.

Phunky
20 Oct 2007, 12:35 AM
This is a great extension of the Paging Toolbar and is something i think should be included by default.

Thanks for the plugin rubensr it will come in handy

jay@moduscreate.com
20 Oct 2007, 11:16 AM
I think this is a great addition. I think it would be of great value if you allowed custom data entry and a 'return key' listener and/or update button.

Here is an example of what i mean. I need to add a 'return key' listener for the combo box.
http://tdg-i.com/img/customers/mikechabot/gridtest.html

Just a suggestion of course. :)

battisti
24 Jan 2008, 3:37 PM
Other plugin very good is the Ext.ux.Andrie.pPageSize

http://extjs.com/learn/Plugin:pPageSize

u39kun
31 Mar 2008, 10:18 AM
Thanks for the PageSize plugin!
Works very well!

tarini
3 Apr 2008, 2:12 PM
thanks!

very good plugin :)


i've added a little chear for i18n (i'm italian and i have an italian app)



Ext.namespace('Ext.ux');

Ext.ux.PageSizePlugin = function(itemsPerPageText) {
this.itemsPerPageText = itemsPerPageText || "items per page";
Ext.ux.PageSizePlugin.superclass.constructor.call(this, {
store: new Ext.data.SimpleStore({
fields: ['text', 'value'],
data: [['10', 10], ['20', 20], ['30', 30], ['50', 50], ['100', 100]]
}),
mode: 'local',
displayField: 'text',
valueField: 'value',
editable: false,
allowBlank: false,
triggerAction: 'all',
width: 40
});
};

Ext.extend(Ext.ux.PageSizePlugin, Ext.form.ComboBox, {
init: function(paging) {
paging.on('render', this.onInitView, this);
},

onInitView: function(paging) {
paging.add('-',
this,
this.itemsPerPageText
);
this.setValue(paging.pageSize);
this.on('select', this.onPageSizeChanged, paging);
},

onPageSizeChanged: function(combo) {
this.pageSize = parseInt(combo.getValue());
this.doLoad(0);
}
});


usage:


plugins: [new Ext.ux.PageSizePlugin("record per pagina")]



bye :P

katakwar
10 Jun 2009, 2:02 PM
Thanks a lot, your examples are making our(Developers) life easy :-).

lassaad
12 Jun 2009, 12:37 AM
Thank you so much =D>
It's very usefull for me

Best regards,
Lassaad

Chief Vas
15 Dec 2009, 7:50 AM
Thanks, works great.=D> I'm surprised this isn't built in to the paging toolbar. Works in 3.0 in case anyone was wondering.

Lmouse
16 Dec 2009, 9:59 PM
Nice plugin =D>

dotnetwise
22 Mar 2010, 1:33 AM
This plugin is out of date. ExtJS is now at version 3.1 / 3.2!!
Also I can't enter custom typed values in the combo box nor I can make it persistible:(

Gunjan
15 May 2010, 4:42 AM
Reang,

To use the plugin, you need to add it to the PagingToolbar creation:



var myPagingToolbar = new Ext.PagingToolbar({
displayInfo: true,
emptyMsg: 'Nothing to show',
store: this.store,
plugins: [new Ext.ux.PageSizePlugin()]
});


and then just add it to the 'bbar' config option of the grid.



Using the above code in bbar plugin config option, the combo is rendered after DisplayMsg but if I want to put my combo just after refreshing icon in pagebar then how can i do that.

Regards
Gunjan