This post originated from an RSS feed registered with Ruby Buzz
by Edward Spencer.
Original Post: ExtJS grid page size - letting the user decide
Feed Title: Ed's Elite blog
Feed URL: http://feeds2.feedburner.com/EdSpencer
Feed Description: Ruby on Rails development, Git issues and ExtJS/JavaScript
Sometimes you'll be using a Paging Toolbar on a grid and need to give the user the ability to change the number of records per page. One way of doing this is by adding a combobox to the toolbar:
var combo = new Ext.form.ComboBox({ name : 'perpage', width: 40, store: new Ext.data.ArrayStore({ fields: ['id'], data : [ ['15'], ['25'], ['50'] ] }), mode : 'local', value: '15',
We've set up a simple combo box which allows the user to choose between 15, 25 and 50 records per page. Now let's set up a Paging Toolbar, and a listener to take action when the user changes the selection in the combo box:
var bbar = new Ext.PagingToolbar({ store: store, //the store you use in your grid displayInfo: true, items : [ '-', 'Per Page: ', combo ] });
var grid = new Ext.grid.GridPanel({ //your grid setup here...
bbar: bbar });
If the user needs to be able to enter her own page size, replace the ComboBox with an Ext.form.NumberField, and attach the event listener to the field's 'keypress' event.