PDA

View Full Version : PageSize plugin for PagingToolbar


rubensr
10-05-2007, 12:48 AM
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
10-05-2007, 01:06 AM
Thanks for extension!

reang
10-05-2007, 03:48 AM
would you please tell me how to apply this plugin on grid.

galdaka
10-05-2007, 04:21 AM
Thanks!! Good work!!

rubensr
10-05-2007, 08: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
10-09-2007, 07:23 AM
Nice plugin ! =D>

hubo1505
10-10-2007, 09:58 PM
good job!

jo2008
10-12-2007, 06: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
10-12-2007, 12:04 PM
how do i change the width of the combobox in an instance?

rubensr
10-14-2007, 10: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
10-15-2007, 08:27 AM
Another question!
how do i get the curent page size into a variable that i can use later?

rubensr
10-16-2007, 09: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
10-20-2007, 04: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

jgarcia@tdg-i.com
10-20-2007, 03:16 PM
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
01-24-2008, 06:37 PM
Other plugin very good is the Ext.ux.Andrie.pPageSize

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

u39kun
03-31-2008, 02:18 PM
Thanks for the PageSize plugin!
Works very well!

tarini
04-03-2008, 06: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
06-10-2009, 06:02 PM
Thanks a lot, your examples are making our(Developers) life easy :-).

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

Best regards,
Lassaad