1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-toolbar.Paging-method-constructor'><span id='Ext-toolbar.Paging'>/**
2 </span></span> * @class Ext.toolbar.Paging
3 * @extends Ext.toolbar.Toolbar
4 * <p>As the amount of records increases, the time required for the browser to render
5 * them increases. Paging is used to reduce the amount of data exchanged with the client.
6 * Note: if there are more records/rows than can be viewed in the available screen area, vertical
7 * scrollbars will be added.</p>
8 * <p>Paging is typically handled on the server side (see exception below). The client sends
9 * parameters to the server side, which the server needs to interpret and then respond with the
10 * appropriate data.</p>
11 * <p><b>Ext.toolbar.Paging</b> is a specialized toolbar that is bound to a {@link Ext.data.Store}
12 * and provides automatic paging control. This Component {@link Ext.data.Store#load load}s blocks
13 * of data into the <tt>{@link #store}</tt> by passing {@link Ext.data.Store#paramNames paramNames} used for
14 * paging criteria.</p>
16 * {@img Ext.toolbar.Paging/Ext.toolbar.Paging.png Ext.toolbar.Paging component}
18 * <p>PagingToolbar is typically used as one of the Grid's toolbars:</p>
19 * <pre><code>
20 * var itemsPerPage = 2; // set the number of items you want per page
22 * var store = Ext.create('Ext.data.Store', {
25 * fields:['name', 'email', 'phone'],
26 * pageSize: itemsPerPage, // items per page
29 * url: 'pagingstore.js', // url that will load data with respect to start and limit params
33 * totalProperty: 'total'
38 * // specify segment of data you want to load using params
46 * Ext.create('Ext.grid.Panel', {
50 * {header: 'Name', dataIndex: 'name'},
51 * {header: 'Email', dataIndex: 'email', flex:1},
52 * {header: 'Phone', dataIndex: 'phone'}
57 * xtype: 'pagingtoolbar',
58 * store: store, // same store GridPanel is using
62 * renderTo: Ext.getBody()
64 * </code></pre>
66 * <p>To use paging, pass the paging requirements to the server when the store is first loaded.</p>
67 * <pre><code>
70 // specify params for the first page load if using paging
77 * </code></pre>
79 * <p>If using {@link Ext.data.Store#autoLoad store's autoLoad} configuration:</p>
80 * <pre><code>
81 var myStore = new Ext.data.Store({
82 {@link Ext.data.Store#autoLoad autoLoad}: {start: 0, limit: 25},
85 * </code></pre>
87 * <p>The packet sent back from the server would have this form:</p>
88 * <pre><code>
90 "success": true,
91 "results": 2000,
92 "rows": [ // <b>*Note:</b> this must be an Array
93 { "id": 1, "name": "Bill", "occupation": "Gardener" },
94 { "id": 2, "name": "Ben", "occupation": "Horticulturalist" },
96 { "id": 25, "name": "Sue", "occupation": "Botanist" }
99 * </code></pre>
100 * <p><u>Paging with Local Data</u></p>
101 * <p>Paging can also be accomplished with local data using extensions:</p>
102 * <div class="mdetail-params"><ul>
103 * <li><a href="http://sencha.com/forum/showthread.php?t=71532">Ext.ux.data.PagingStore</a></li>
104 * <li>Paging Memory Proxy (examples/ux/PagingMemoryProxy.js)</li>
105 * </ul></div>
106 * @constructor Create a new PagingToolbar
107 * @param {Object} config The config object
108 * @xtype pagingtoolbar
110 Ext.define('Ext.toolbar.Paging', {
111 extend: 'Ext.toolbar.Toolbar',
112 alias: 'widget.pagingtoolbar',
113 alternateClassName: 'Ext.PagingToolbar',
114 requires: ['Ext.toolbar.TextItem', 'Ext.form.field.Number'],
115 <span id='Ext-toolbar.Paging-cfg-store'> /**
116 </span> * @cfg {Ext.data.Store} store
117 * The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
119 <span id='Ext-toolbar.Paging-cfg-displayInfo'> /**
120 </span> * @cfg {Boolean} displayInfo
121 * <tt>true</tt> to display the displayMsg (defaults to <tt>false</tt>)
124 <span id='Ext-toolbar.Paging-cfg-prependButtons'> /**
125 </span> * @cfg {Boolean} prependButtons
126 * <tt>true</tt> to insert any configured <tt>items</tt> <i>before</i> the paging buttons.
127 * Defaults to <tt>false</tt>.
129 prependButtons: false,
130 <span id='Ext-toolbar.Paging-cfg-displayMsg'> /**
131 </span> * @cfg {String} displayMsg
132 * The paging status message to display (defaults to <tt>'Displaying {0} - {1} of {2}'</tt>).
133 * Note that this string is formatted using the braced numbers <tt>{0}-{2}</tt> as tokens
134 * that are replaced by the values for start, end and total respectively. These tokens should
135 * be preserved when overriding this string if showing those values is desired.
137 displayMsg : 'Displaying {0} - {1} of {2}',
138 <span id='Ext-toolbar.Paging-cfg-emptyMsg'> /**
139 </span> * @cfg {String} emptyMsg
140 * The message to display when no records are found (defaults to 'No data to display')
142 emptyMsg : 'No data to display',
143 <span id='Ext-toolbar.Paging-cfg-beforePageText'> /**
144 </span> * @cfg {String} beforePageText
145 * The text displayed before the input item (defaults to <tt>'Page'</tt>).
147 beforePageText : 'Page',
148 <span id='Ext-toolbar.Paging-cfg-afterPageText'> /**
149 </span> * @cfg {String} afterPageText
150 * Customizable piece of the default paging text (defaults to <tt>'of {0}'</tt>). Note that
151 * this string is formatted using <tt>{0}</tt> as a token that is replaced by the number of
152 * total pages. This token should be preserved when overriding this string if showing the
153 * total page count is desired.
155 afterPageText : 'of {0}',
156 <span id='Ext-toolbar.Paging-cfg-firstText'> /**
157 </span> * @cfg {String} firstText
158 * The quicktip text displayed for the first page button (defaults to <tt>'First Page'</tt>).
159 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
161 firstText : 'First Page',
162 <span id='Ext-toolbar.Paging-cfg-prevText'> /**
163 </span> * @cfg {String} prevText
164 * The quicktip text displayed for the previous page button (defaults to <tt>'Previous Page'</tt>).
165 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
167 prevText : 'Previous Page',
168 <span id='Ext-toolbar.Paging-cfg-nextText'> /**
169 </span> * @cfg {String} nextText
170 * The quicktip text displayed for the next page button (defaults to <tt>'Next Page'</tt>).
171 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
173 nextText : 'Next Page',
174 <span id='Ext-toolbar.Paging-cfg-lastText'> /**
175 </span> * @cfg {String} lastText
176 * The quicktip text displayed for the last page button (defaults to <tt>'Last Page'</tt>).
177 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
179 lastText : 'Last Page',
180 <span id='Ext-toolbar.Paging-cfg-refreshText'> /**
181 </span> * @cfg {String} refreshText
182 * The quicktip text displayed for the Refresh button (defaults to <tt>'Refresh'</tt>).
183 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
185 refreshText : 'Refresh',
186 <span id='Ext-toolbar.Paging-cfg-inputItemWidth'> /**
187 </span> * @cfg {Number} inputItemWidth
188 * The width in pixels of the input field used to display and change the current page number (defaults to 30).
192 <span id='Ext-toolbar.Paging-method-getPagingItems'> /**
193 </span> * Gets the standard paging items in the toolbar
196 getPagingItems: function() {
201 tooltip: me.firstText,
202 overflowText: me.firstText,
203 iconCls: Ext.baseCSSPrefix + 'tbar-page-first',
205 handler: me.moveFirst,
209 tooltip: me.prevText,
210 overflowText: me.prevText,
211 iconCls: Ext.baseCSSPrefix + 'tbar-page-prev',
213 handler: me.movePrevious,
219 xtype: 'numberfield',
222 cls: Ext.baseCSSPrefix + 'tbar-page-number',
223 allowDecimals: false,
226 enableKeyEvents: true,
229 width: me.inputItemWidth,
233 keydown: me.onPagingKeyDown,
234 blur: me.onPagingBlur
238 itemId: 'afterTextItem',
239 text: Ext.String.format(me.afterPageText, 1)
244 tooltip: me.nextText,
245 overflowText: me.nextText,
246 iconCls: Ext.baseCSSPrefix + 'tbar-page-next',
248 handler: me.moveNext,
252 tooltip: me.lastText,
253 overflowText: me.lastText,
254 iconCls: Ext.baseCSSPrefix + 'tbar-page-last',
256 handler: me.moveLast,
262 tooltip: me.refreshText,
263 overflowText: me.refreshText,
264 iconCls: Ext.baseCSSPrefix + 'tbar-loading',
265 handler: me.doRefresh,
270 initComponent : function(){
272 pagingItems = me.getPagingItems(),
273 userItems = me.items || me.buttons || [];
275 if (me.prependButtons) {
276 me.items = userItems.concat(pagingItems);
278 me.items = pagingItems.concat(userItems);
282 if (me.displayInfo) {
283 me.items.push('->');
284 me.items.push({xtype: 'tbtext', itemId: 'displayItem'});
290 <span id='Ext-toolbar.Paging-event-change'> /**
291 </span> * @event change
292 * Fires after the active page has been changed.
293 * @param {Ext.toolbar.Paging} this
294 * @param {Object} pageData An object that has these properties:<ul>
295 * <li><code>total</code> : Number <div class="sub-desc">The total number of records in the dataset as
296 * returned by the server</div></li>
297 * <li><code>currentPage</code> : Number <div class="sub-desc">The current page number</div></li>
298 * <li><code>pageCount</code> : Number <div class="sub-desc">The total number of pages (calculated from
299 * the total number of records in the dataset as returned by the server and the current {@link #pageSize})</div></li>
300 * <li><code>toRecord</code> : Number <div class="sub-desc">The starting record index for the current page</div></li>
301 * <li><code>fromRecord</code> : Number <div class="sub-desc">The ending record index for the current page</div></li>
305 <span id='Ext-toolbar.Paging-event-beforechange'> /**
306 </span> * @event beforechange
307 * Fires just before the active page is changed.
308 * Return false to prevent the active page from being changed.
309 * @param {Ext.toolbar.Paging} this
310 * @param {Number} page The page number that will be loaded on change
314 me.on('afterlayout', me.onLoad, me, {single: true});
316 me.bindStore(me.store, true);
319 updateInfo : function(){
321 displayItem = me.child('#displayItem'),
323 pageData = me.getPageData(),
327 count = store.getCount();
331 msg = Ext.String.format(
338 displayItem.setText(msg);
339 me.doComponentLayout();
355 pageData = me.getPageData();
356 currPage = pageData.currentPage;
357 pageCount = pageData.pageCount;
358 afterText = Ext.String.format(me.afterPageText, isNaN(pageCount) ? 1 : pageCount);
360 me.child('#afterTextItem').setText(afterText);
361 me.child('#inputItem').setValue(currPage);
362 me.child('#first').setDisabled(currPage === 1);
363 me.child('#prev').setDisabled(currPage === 1);
364 me.child('#next').setDisabled(currPage === pageCount);
365 me.child('#last').setDisabled(currPage === pageCount);
366 me.child('#refresh').enable();
368 me.fireEvent('change', me, pageData);
372 getPageData : function(){
373 var store = this.store,
374 totalCount = store.getTotalCount();
378 currentPage : store.currentPage,
379 pageCount: Math.ceil(totalCount / store.pageSize),
380 //pageCount : store.getPageCount(),
381 fromRecord: ((store.currentPage - 1) * store.pageSize) + 1,
382 toRecord: Math.min(store.currentPage * store.pageSize, totalCount)
388 onLoadError : function(){
389 if (!this.rendered) {
392 this.child('#refresh').enable();
396 readPageFromInput : function(pageData){
397 var v = this.child('#inputItem').getValue(),
398 pageNum = parseInt(v, 10);
400 if (!v || isNaN(pageNum)) {
401 this.child('#inputItem').setValue(pageData.currentPage);
407 onPagingFocus : function(){
408 this.child('#inputItem').select();
412 onPagingBlur : function(e){
413 var curPage = this.getPageData().currentPage;
414 this.child('#inputItem').setValue(curPage);
418 onPagingKeyDown : function(field, e){
420 pageData = this.getPageData(),
421 increment = e.shiftKey ? 10 : 1,
427 pageNum = me.readPageFromInput(pageData);
428 if (pageNum !== false) {
429 pageNum = Math.min(Math.max(1, pageNum), pageData.total);
430 if(me.fireEvent('beforechange', me, pageNum) !== false){
431 me.store.loadPage(pageNum);
434 } else if (k == e.HOME || k == e.END) {
436 pageNum = k == e.HOME ? 1 : pageData.pageCount;
437 field.setValue(pageNum);
438 } else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN) {
440 pageNum = me.readPageFromInput(pageData);
442 if (k == e.DOWN || k == e.PAGEDOWN) {
445 pageNum += increment;
446 if (pageNum >= 1 && pageNum <= pageData.pages) {
447 field.setValue(pageNum);
454 beforeLoad : function(){
455 if(this.rendered && this.refresh){
456 this.refresh.disable();
461 doLoad : function(start){
462 if(this.fireEvent('beforechange', this, o) !== false){
467 <span id='Ext-toolbar.Paging-method-moveFirst'> /**
468 </span> * Move to the first page, has the same effect as clicking the 'first' button.
470 moveFirst : function(){
472 if(me.fireEvent('beforechange', me, 1) !== false){
473 me.store.loadPage(1);
477 <span id='Ext-toolbar.Paging-method-movePrevious'> /**
478 </span> * Move to the previous page, has the same effect as clicking the 'previous' button.
480 movePrevious : function(){
482 prev = me.store.currentPage - 1;
484 if(me.fireEvent('beforechange', me, prev) !== false){
485 me.store.previousPage();
489 <span id='Ext-toolbar.Paging-method-moveNext'> /**
490 </span> * Move to the next page, has the same effect as clicking the 'next' button.
492 moveNext : function(){
494 if(me.fireEvent('beforechange', me, me.store.currentPage + 1) !== false){
499 <span id='Ext-toolbar.Paging-method-moveLast'> /**
500 </span> * Move to the last page, has the same effect as clicking the 'last' button.
502 moveLast : function(){
504 last = this.getPageData().pageCount;
506 if(me.fireEvent('beforechange', me, last) !== false){
507 me.store.loadPage(last);
511 <span id='Ext-toolbar.Paging-method-doRefresh'> /**
512 </span> * Refresh the current page, has the same effect as clicking the 'refresh' button.
514 doRefresh : function(){
516 current = me.store.currentPage;
518 if(me.fireEvent('beforechange', me, current) !== false){
519 me.store.loadPage(current);
523 <span id='Ext-toolbar.Paging-method-bindStore'> /**
524 </span> * Binds the paging toolbar to the specified {@link Ext.data.Store}
525 * @param {Store} store The store to bind to this toolbar
526 * @param {Boolean} initial (Optional) true to not remove listeners
528 bindStore : function(store, initial){
531 if (!initial && me.store) {
532 if(store !== me.store && me.store.autoDestroy){
535 me.store.un('beforeload', me.beforeLoad, me);
536 me.store.un('load', me.onLoad, me);
537 me.store.un('exception', me.onLoadError, me);
544 store = Ext.data.StoreManager.lookup(store);
547 beforeload: me.beforeLoad,
549 exception: me.onLoadError
555 <span id='Ext-toolbar.Paging-method-unbind'> /**
556 </span> * Unbinds the paging toolbar from the specified {@link Ext.data.Store} <b>(deprecated)</b>
557 * @param {Ext.data.Store} store The data store to unbind
559 unbind : function(store){
560 this.bindStore(null);
563 <span id='Ext-toolbar.Paging-method-bind'> /**
564 </span> * Binds the paging toolbar to the specified {@link Ext.data.Store} <b>(deprecated)</b>
565 * @param {Ext.data.Store} store The data store to bind
567 bind : function(store){
568 this.bindStore(store);
572 onDestroy : function(){
573 this.bindStore(null);
577 </pre></pre></body></html>