2
* Ext JS Library 3.0 RC2
3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.PagingToolbar
11
* @extends Ext.Toolbar
12
* <p>As the amount of records increases, the time required for the browser to render
13
* them increases. Paging is used to reduce the amount of data exchanged with the client.
14
* Note: if there are more records/rows than can be viewed in the available screen area, vertical
15
* scrollbars will be added.</p>
16
* <p>Paging is typically handled on the server side (see exception below). The client sends
17
* parameters to the server side, which the server needs to interpret and then respond with the
18
* approprate data.</p>
19
* <p><b>Ext.PagingToolbar</b> is a specialized toolbar that is bound to a {@link Ext.data.Store}
20
* and provides automatic paging control. This Component {@link Ext.data.Store#load load}s blocks
21
* of data into the <tt>{@link #store}</tt> by passing {@link #paramNames parameters} used for
22
* paging criteria.</p>
23
* <p>PagingToolbar is typically used as one of the Grid's toolbars:</p>
25
Ext.QuickTips.init(); // to display button quicktips
27
var myStore = new Ext.data.Store({
31
var myPageSize = 25; // server script should only send back 25 items
33
var grid = new Ext.grid.GridPanel({
36
bbar: new Ext.PagingToolbar({
37
{@link #store}: myStore, // grid and PagingToolbar using same store
38
{@link #displayInfo}: true,
39
{@link #pageSize}: myPageSize,
40
{@link #prependButtons}: true,
48
* <p>To use paging, pass the paging requirements to the server when the store is first loaded.</p>
52
start: 0, // specify params for the first page load if using paging
57
* <p><u>Paging with Local Data</u></p>
58
* <p>Paging can also be accomplished with local data using extensions:</p>
59
* <div class="mdetail-params"><ul>
60
* <li><a href="http://extjs.com/forum/showthread.php?t=57386">Ext.ux.data.PagingStore</a></li>
61
* <li>Paging Memory Proxy (examples/locale/PagingMemoryProxy.js)</li>
64
* Create a new PagingToolbar
65
* @param {Object} config The config object
72
Ext.PagingToolbar = Ext.extend(Ext.Toolbar, {
74
* @cfg {Ext.data.Store} store
75
* The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
78
* @cfg {Boolean} displayInfo
79
* <tt>true</tt> to display the displayMsg (defaults to <tt>false</tt>)
82
* @cfg {Number} pageSize
83
* The number of records to display per page (defaults to <tt>20</tt>)
87
* @cfg {Boolean} prependButtons
88
* <tt>true</tt> to insert any configured <tt>items</tt> <i>before</i> the paging buttons.
89
* Defaults to <tt>false</tt>.
92
* @cfg {String} displayMsg
93
* The paging status message to display (defaults to <tt>"Displaying {0} - {1} of {2}"</tt>).
94
* Note that this string is formatted using the braced numbers <tt>{0}-{2}</tt> as tokens
95
* that are replaced by the values for start, end and total respectively. These tokens should
96
* be preserved when overriding this string if showing those values is desired.
98
displayMsg : 'Displaying {0} - {1} of {2}',
100
* @cfg {String} emptyMsg
101
* The message to display when no records are found (defaults to "No data to display")
103
emptyMsg : 'No data to display',
105
* @cfg {String} beforePageText
106
* The text displayed before the input item (defaults to <tt>"Page"</tt>).
108
beforePageText : "Page",
110
* @cfg {String} afterPageText
111
* Customizable piece of the default paging text (defaults to <tt>"of {0}"</tt>). Note that
112
* this string is formatted using <tt>{0}</tt> as a token that is replaced by the number of
113
* total pages. This token should be preserved when overriding this string if showing the
114
* total page count is desired.
116
afterPageText : "of {0}",
118
* @cfg {String} firstText
119
* The quicktip text displayed for the first page button (defaults to <tt>"First Page"</tt>).
120
* <b>Note</b>: quick tips must be initialized for the quicktip to show.
122
firstText : "First Page",
124
* @cfg {String} prevText
125
* The quicktip text displayed for the previous page button (defaults to <tt>"Previous Page"</tt>).
126
* <b>Note</b>: quick tips must be initialized for the quicktip to show.
128
prevText : "Previous Page",
130
* @cfg {String} nextText
131
* The quicktip text displayed for the next page button (defaults to <tt>"Next Page"</tt>).
132
* <b>Note</b>: quick tips must be initialized for the quicktip to show.
134
nextText : "Next Page",
136
* @cfg {String} lastText
137
* The quicktip text displayed for the last page button (defaults to <tt>"Last Page"</tt>).
138
* <b>Note</b>: quick tips must be initialized for the quicktip to show.
140
lastText : "Last Page",
142
* @cfg {String} lastText
143
* The quicktip text displayed for the Refresh button (defaults to <tt>"Refresh"</tt>).
144
* <b>Note</b>: quick tips must be initialized for the quicktip to show.
146
refreshText : "Refresh",
149
* Object mapping of parameter names used for load calls. This property is affected by
150
* See also {@link Ext.data.Store#paramNames}, but is initially set to:
151
* <pre>{start: 'start', limit: 'limit'}</pre>
153
paramNames : {start: 'start', limit: 'limit'},
156
* The number of records to display per page. See also <tt>{@link #cursor}</tt>.
162
* Indicator for the record position. This property might be used to get the active page
163
* number for example:<pre><code>
164
* // t is reference to the paging toolbar instance
165
* var activePage = Math.ceil((t.cursor + t.pageSize) / t.pageSize);
171
initComponent: function(){
172
var pagingItems = [this.first = new T.Button({
173
tooltip: this.firstText,
174
iconCls: "x-tbar-page-first",
176
handler: this.onClick,
178
}), this.prev = new T.Button({
179
tooltip: this.prevText,
180
iconCls: "x-tbar-page-prev",
182
handler: this.onClick,
184
}), '-', this.beforePageText,
185
this.inputItem = new T.Item({
192
cls: "x-tbar-page-number"
194
}), this.afterTextItem = new T.TextItem({
195
text: String.format(this.afterPageText, 1)
196
}), '-', this.next = new T.Button({
197
tooltip: this.nextText,
198
iconCls: "x-tbar-page-next",
200
handler: this.onClick,
202
}), this.last = new T.Button({
203
tooltip: this.lastText,
204
iconCls: "x-tbar-page-last",
206
handler: this.onClick,
208
}), '-', this.refresh = new T.Button({
209
tooltip: this.refreshText,
210
iconCls: "x-tbar-loading",
211
handler: this.onClick,
216
var userItems = this.items || this.buttons || [];
217
if (this.prependButtons) {
218
this.items = userItems.concat(pagingItems);
220
this.items = pagingItems.concat(userItems);
223
if(this.displayInfo){
224
this.items.push('->');
225
this.items.push(this.displayItem = new T.TextItem({}));
227
Ext.PagingToolbar.superclass.initComponent.call(this);
231
* Fires after the active page has been changed.
232
* @param {Ext.PagingToolbar} this
233
* @param {Object} pageData An object that has these properties:<ul>
234
* <li><code>total</code> : Number <div class="sub-desc">The total number of records in the dataset as
235
* returned by the server</div></li>
236
* <li><code>activePage</code> : Number <div class="sub-desc">The current page number</div></li>
237
* <li><code>pages</code> : Number <div class="sub-desc">The total number of pages (calculated from
238
* the total number of records in the dataset as returned by the server and the current {@link #pageSize})</div></li>
243
* @event beforechange
244
* Fires just before the active page is changed.
245
* Return false to prevent the active page from being changed.
246
* @param {Ext.PagingToolbar} this
247
* @param {Object} params An object hash of the parameters which the PagingToolbar will send when
248
* loading the required page. This will contain:<ul>
249
* <li><code>start</code> : Number <div class="sub-desc">The starting row number for the next page of records to
250
* be retrieved from the server</div></li>
251
* <li><code>limit</code> : Number <div class="sub-desc">The number of records to be retrieved from the server</div></li>
253
* <p>(note: the names of the <b>start</b> and <b>limit</b> properties are determined
254
* by the store's {@link Ext.data.Store#paramNames paramNames} property.)</p>
255
* <p>Parameters may be added as required in the event handler.</p>
259
this.on('afterlayout', this.onFirstLayout, this, {single: true});
261
this.bindStore(this.store);
265
onFirstLayout: function(ii) {
266
this.mon(this.inputItem.el, "keydown", this.onPagingKeyDown, this);
267
this.mon(this.inputItem.el, "blur", this.onPagingBlur, this);
268
this.mon(this.inputItem.el, "focus", this.onPagingFocus, this);
270
this.field = this.inputItem.el.dom;
272
this.onLoad.apply(this, this.dsLoaded);
277
updateInfo : function(){
278
if(this.displayItem){
279
var count = this.store.getCount();
280
var msg = count == 0 ?
284
this.cursor+1, this.cursor+count, this.store.getTotalCount()
286
this.displayItem.setText(msg);
291
onLoad : function(store, r, o){
293
this.dsLoaded = [store, r, o];
296
this.cursor = (o.params && o.params[this.paramNames.start]) ? o.params[this.paramNames.start] : 0;
297
var d = this.getPageData(), ap = d.activePage, ps = d.pages;
299
this.afterTextItem.setText(String.format(this.afterPageText, d.pages));
300
this.field.value = ap;
301
this.first.setDisabled(ap == 1);
302
this.prev.setDisabled(ap == 1);
303
this.next.setDisabled(ap == ps);
304
this.last.setDisabled(ap == ps);
305
this.refresh.enable();
307
this.fireEvent('change', this, d);
311
getPageData : function(){
312
var total = this.store.getTotalCount();
315
activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
316
pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
321
* Change the active page
322
* @param {Integer} page The page to display
324
changePage: function(page){
325
this.doLoad(((page-1) * this.pageSize).constrain(0, this.store.getTotalCount()));
329
onLoadError : function(){
333
this.refresh.enable();
337
readPage : function(d){
338
var v = this.field.value, pageNum;
339
if (!v || isNaN(pageNum = parseInt(v, 10))) {
340
this.field.value = d.activePage;
346
onPagingFocus: function(){
351
onPagingBlur: function(e){
352
this.field.value = this.getPageData().activePage;
356
onPagingKeyDown : function(e){
357
var k = e.getKey(), d = this.getPageData(), pageNum;
360
pageNum = this.readPage(d);
361
if(pageNum !== false){
362
pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
363
this.doLoad(pageNum * this.pageSize);
365
}else if (k == e.HOME || k == e.END){
367
pageNum = k == e.HOME ? 1 : d.pages;
368
this.field.value = pageNum;
369
}else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){
371
if((pageNum = this.readPage(d))){
372
var increment = e.shiftKey ? 10 : 1;
373
if(k == e.DOWN || k == e.PAGEDOWN){
376
pageNum += increment;
377
if(pageNum >= 1 & pageNum <= d.pages){
378
this.field.value = pageNum;
385
beforeLoad : function(){
386
if(this.rendered && this.refresh){
387
this.refresh.disable();
392
doLoad : function(start){
393
var o = {}, pn = this.paramNames;
395
o[pn.limit] = this.pageSize;
396
if(this.fireEvent('beforechange', this, o) !== false){
397
this.store.load({params:o});
402
onClick : function(button){
403
var store = this.store;
409
this.doLoad(Math.max(0, this.cursor-this.pageSize));
412
this.doLoad(this.cursor+this.pageSize);
415
var total = store.getTotalCount();
416
var extra = total % this.pageSize;
417
var lastStart = extra ? (total - extra) : total-this.pageSize;
418
this.doLoad(lastStart);
421
this.doLoad(this.cursor);
427
* Binds the paging toolbar to the specified {@link Ext.data.Store}
428
* @param {Store} store The store to bind to this view
430
bindStore : function(store, initial){
431
if(!initial && this.store){
432
this.store.un("beforeload", this.beforeLoad, this);
433
this.store.un("load", this.onLoad, this);
434
this.store.un("loadexception", this.onLoadError, this);
435
this.store.un("exception", this.onLoadError, this);
436
if(store !== this.store && this.store.autoDestroy){
437
this.store.destroy();
441
store = Ext.StoreMgr.lookup(store);
444
beforeload: this.beforeLoad,
446
loadexception: this.onLoadError,
447
exception: this.onLoadError
449
this.paramNames.start = store.paramNames.start;
450
this.paramNames.limit = store.paramNames.limit;
452
if (store.getCount() > 0){
453
this.onLoad(store, null, {});
460
* Unbinds the paging toolbar from the specified {@link Ext.data.Store} <b>(deprecated)</b>
461
* @param {Ext.data.Store} store The data store to unbind
463
unbind : function(store){
464
this.bindStore(null);
468
* Binds the paging toolbar to the specified {@link Ext.data.Store} <b>(deprecated)</b>
469
* @param {Ext.data.Store} store The data store to bind
471
bind : function(store){
472
this.bindStore(store);
476
onDestroy : function(){
477
this.bindStore(null);
478
Ext.PagingToolbar.superclass.onDestroy.call(this);
483
Ext.reg('paging', Ext.PagingToolbar);
b'\\ No newline at end of file'