/**
* @class Ext.PagingToolbar
* @extends Ext.Toolbar
*As the amount of records increases, the time required for the browser to render
* them increases. Paging is used to reduce the amount of data exchanged with the client.
* Note: if there are more records/rows than can be viewed in the available screen area, vertical
* scrollbars will be added.
*Paging is typically handled on the server side (see exception below). The client sends
* parameters to the server side, which the server needs to interpret and then respond with the
* approprate data.
*Ext.PagingToolbar is a specialized toolbar that is bound to a {@link Ext.data.Store}
* and provides automatic paging control. This Component {@link Ext.data.Store#load load}s blocks
* of data into the {@link #store} by passing {@link Ext.data.Store#paramNames paramNames} used for
* paging criteria.
*PagingToolbar is typically used as one of the Grid's toolbars:
*
Ext.QuickTips.init(); // to display button quicktips
var myStore = new Ext.data.Store({
...
});
var myPageSize = 25; // server script should only send back 25 items
var grid = new Ext.grid.GridPanel({
...
store: myStore,
bbar: new Ext.PagingToolbar({
{@link #store}: myStore, // grid and PagingToolbar using same store
{@link #displayInfo}: true,
{@link #pageSize}: myPageSize,
{@link #prependButtons}: true,
items: [
'text 1'
]
})
});
*
*
*To use paging, pass the paging requirements to the server when the store is first loaded.
*
store.load({
params: {
start: 0, // specify params for the first page load if using paging
limit: myPageSize,
foo: 'bar'
}
});
*
*Paging with Local Data
*Paging can also be accomplished with local data using extensions:
*
*- Ext.ux.data.PagingStore
*- Paging Memory Proxy (examples/ux/PagingMemoryProxy.js)
*
* @constructor Create a new PagingToolbar
* @param {Object} config The config object
* @xtype paging
*/
(function() {
var T = Ext.Toolbar;
Ext.PagingToolbar = Ext.extend(Ext.Toolbar, {
/**
* @cfg {Ext.data.Store} store
* The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
*/
/**
* @cfg {Boolean} displayInfo
* true to display the displayMsg (defaults to false)
*/
/**
* @cfg {Number} pageSize
* The number of records to display per page (defaults to 20)
*/
pageSize : 20,
/**
* @cfg {Boolean} prependButtons
* true to insert any configured items before the paging buttons.
* Defaults to false.
*/
/**
* @cfg {String} displayMsg
* The paging status message to display (defaults to 'Displaying {0} - {1} of {2}').
* Note that this string is formatted using the braced numbers {0}-{2} as tokens
* that are replaced by the values for start, end and total respectively. These tokens should
* be preserved when overriding this string if showing those values is desired.
*/
displayMsg : 'Displaying {0} - {1} of {2}',
/**
* @cfg {String} emptyMsg
* The message to display when no records are found (defaults to 'No data to display')
*/
emptyMsg : 'No data to display',
/**
* @cfg {String} beforePageText
* The text displayed before the input item (defaults to 'Page').
*/
beforePageText : 'Page',
/**
* @cfg {String} afterPageText
* Customizable piece of the default paging text (defaults to 'of {0}'). Note that
* this string is formatted using {0} as a token that is replaced by the number of
* total pages. This token should be preserved when overriding this string if showing the
* total page count is desired.
*/
afterPageText : 'of {0}',
/**
* @cfg {String} firstText
* The quicktip text displayed for the first page button (defaults to 'First Page').
* Note: quick tips must be initialized for the quicktip to show.
*/
firstText : 'First Page',
/**
* @cfg {String} prevText
* The quicktip text displayed for the previous page button (defaults to 'Previous Page').
* Note: quick tips must be initialized for the quicktip to show.
*/
prevText : 'Previous Page',
/**
* @cfg {String} nextText
* The quicktip text displayed for the next page button (defaults to 'Next Page').
* Note: quick tips must be initialized for the quicktip to show.
*/
nextText : 'Next Page',
/**
* @cfg {String} lastText
* The quicktip text displayed for the last page button (defaults to 'Last Page').
* Note: quick tips must be initialized for the quicktip to show.
*/
lastText : 'Last Page',
/**
* @cfg {String} refreshText
* The quicktip text displayed for the Refresh button (defaults to 'Refresh').
* Note: quick tips must be initialized for the quicktip to show.
*/
refreshText : 'Refresh',
/**
*Deprecated.
paramNames
should be set in the data store
* (see {@link Ext.data.Store#paramNames}).
*Object mapping of parameter names used for load calls, initially set to:
*{start: 'start', limit: 'limit'}
* @type Object
* @property paramNames
* @deprecated
*/
/**
* The number of records to display per page. See also {@link #cursor}.
* @type Number
* @property pageSize
*/
/**
* Indicator for the record position. This property might be used to get the active page
* number for example:
* // t is reference to the paging toolbar instance
* var activePage = Math.ceil((t.cursor + t.pageSize) / t.pageSize);
*
* @type Number
* @property cursor
*/
initComponent : function(){
var pagingItems = [this.first = new T.Button({
tooltip: this.firstText,
overflowText: this.firstText,
iconCls: 'x-tbar-page-first',
disabled: true,
handler: this.moveFirst,
scope: this
}), this.prev = new T.Button({
tooltip: this.prevText,
overflowText: this.prevText,
iconCls: 'x-tbar-page-prev',
disabled: true,
handler: this.movePrevious,
scope: this
}), '-', this.beforePageText,
this.inputItem = new Ext.form.NumberField({
cls: 'x-tbar-page-number',
allowDecimals: false,
allowNegative: false,
enableKeyEvents: true,
selectOnFocus: true,
listeners: {
scope: this,
keydown: this.onPagingKeyDown,
blur: this.onPagingBlur
}
}), this.afterTextItem = new T.TextItem({
text: String.format(this.afterPageText, 1)
}), '-', this.next = new T.Button({
tooltip: this.nextText,
overflowText: this.nextText,
iconCls: 'x-tbar-page-next',
disabled: true,
handler: this.moveNext,
scope: this
}), this.last = new T.Button({
tooltip: this.lastText,
overflowText: this.lastText,
iconCls: 'x-tbar-page-last',
disabled: true,
handler: this.moveLast,
scope: this
}), '-', this.refresh = new T.Button({
tooltip: this.refreshText,
overflowText: this.refreshText,
iconCls: 'x-tbar-loading',
handler: this.refresh,
scope: this
})];
var userItems = this.items || this.buttons || [];
if (this.prependButtons) {
this.items = userItems.concat(pagingItems);
}else{
this.items = pagingItems.concat(userItems);
}
delete this.buttons;
if(this.displayInfo){
this.items.push('->');
this.items.push(this.displayItem = new T.TextItem({}));
}
Ext.PagingToolbar.superclass.initComponent.call(this);
this.addEvents(
/**
* @event change
* Fires after the active page has been changed.
* @param {Ext.PagingToolbar} this
* @param {Object} pageData An object that has these properties:
total
: Number activePage
: Number pages
: Number start
: Number limit
: Number (note: the names of the start and limit properties are determined
* by the store's {@link Ext.data.Store#paramNames paramNames} property.)
Parameters may be added as required in the event handler.