3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.layout.ToolbarLayout
9 * @extends Ext.layout.ContainerLayout
10 * Layout manager implicitly used by Ext.Toolbar.
12 Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {
18 noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
20 onLayout : function(ct, target){
22 var align = ct.buttonAlign == 'center' ? 'center' : 'left';
23 target.addClass('x-toolbar-layout-ct');
24 target.insertHtml('beforeEnd',
25 '<table cellspacing="0" class="x-toolbar-ct"><tbody><tr><td class="x-toolbar-left" align="' + align + '"><table cellspacing="0"><tbody><tr class="x-toolbar-left-row"></tr></tbody></table></td><td class="x-toolbar-right" align="right"><table cellspacing="0" class="x-toolbar-right-ct"><tbody><tr><td><table cellspacing="0"><tbody><tr class="x-toolbar-right-row"></tr></tbody></table></td><td><table cellspacing="0"><tbody><tr class="x-toolbar-extras-row"></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>');
26 this.leftTr = target.child('tr.x-toolbar-left-row', true);
27 this.rightTr = target.child('tr.x-toolbar-right-row', true);
28 this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
30 var side = ct.buttonAlign == 'right' ? this.rightTr : this.leftTr,
32 items = ct.items.items;
34 for(var i = 0, len = items.length, c; i < len; i++, pos++) {
39 }else if(!c.rendered){
40 c.render(this.insertCell(c, side, pos));
42 if(!c.xtbHidden && !this.isValidParent(c, side.childNodes[pos])){
43 var td = this.insertCell(c, side, pos);
44 td.appendChild(c.getPositionEl().dom);
45 c.container = Ext.get(td);
49 //strip extra empty cells
50 this.cleanup(this.leftTr);
51 this.cleanup(this.rightTr);
52 this.cleanup(this.extrasTr);
53 this.fitToSize(target);
56 cleanup : function(row){
57 var cn = row.childNodes;
58 for(var i = cn.length-1, c; i >= 0 && (c = cn[i]); i--){
65 insertCell : function(c, side, pos){
66 var td = document.createElement('td');
67 td.className='x-toolbar-cell';
68 side.insertBefore(td, side.childNodes[pos]||null);
72 hideItem : function(item){
73 var h = (this.hiddens = this.hiddens || []);
75 item.xtbHidden = true;
76 item.xtbWidth = item.getPositionEl().dom.parentNode.offsetWidth;
80 unhideItem : function(item){
82 item.xtbHidden = false;
83 this.hiddens.remove(item);
84 if(this.hiddens.length < 1){
89 getItemWidth : function(c){
90 return c.hidden ? (c.xtbWidth || 0) : c.getPositionEl().dom.parentNode.offsetWidth;
93 fitToSize : function(t){
94 if(this.container.enableOverflow === false){
97 var w = t.dom.clientWidth,
98 lw = this.lastWidth || 0,
99 iw = t.dom.firstChild.offsetWidth,
100 clipWidth = w - this.triggerWidth,
105 if(iw > w || (this.hiddens && w >= lw)){
106 var i, items = this.container.items.items,
107 len = items.length, c,
110 for(i = 0; i < len; i++) {
113 loopWidth += this.getItemWidth(c);
114 if(loopWidth > clipWidth){
115 if(!(c.hidden || c.xtbHidden)){
118 }else if(c.xtbHidden){
126 if(!this.lastOverflow){
127 this.container.fireEvent('overflowchange', this.container, true);
128 this.lastOverflow = true;
134 if(this.lastOverflow){
135 this.container.fireEvent('overflowchange', this.container, false);
136 this.lastOverflow = false;
141 createMenuConfig : function(c, hideOnClick){
142 var cfg = Ext.apply({}, c.initialConfig),
143 group = c.toggleGroup;
146 text: c.overflowText || c.text,
150 disabled: c.disabled,
154 hideOnClick: hideOnClick
156 if(group || c.enableToggle){
161 checkchange: function(item, checked){
174 addComponentToMenu : function(m, c){
175 if(c instanceof Ext.Toolbar.Separator){
177 }else if(Ext.isFunction(c.isXType)){
178 if(c.isXType('splitbutton')){
179 m.add(this.createMenuConfig(c, true));
180 }else if(c.isXType('button')){
181 m.add(this.createMenuConfig(c, !c.menu));
182 }else if(c.isXType('buttongroup')){
183 c.items.each(function(item){
184 this.addComponentToMenu(m, item);
190 clearMenu : function(){
191 var m = this.moreMenu;
193 m.items.each(function(item){
200 beforeMoreShow : function(m){
201 var h = this.container.items.items,
205 needsSep = function(group, item){
206 return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
211 for(var i = 0; i < len; i++){
214 if(prev && (needsSep(c, prev) || needsSep(prev, c))){
217 this.addComponentToMenu(m, c);
221 // put something so the menu isn't empty
222 // if no compatible items found
223 if(m.items.length < 1){
224 m.add(this.noItemsMenuText);
228 initMore : function(){
230 this.moreMenu = new Ext.menu.Menu({
232 beforeshow: this.beforeMoreShow,
236 this.moreMenu.ownerCt = this.container;
237 this.more = new Ext.Button({
238 iconCls: 'x-toolbar-more-icon',
239 cls: 'x-toolbar-more',
242 var td = this.insertCell(this.more, this.extrasTr, 100);
243 this.more.render(td);
247 onRemove : function(c){
250 delete this.extrasTr;
251 Ext.layout.ToolbarLayout.superclass.onRemove.call(this, c);
254 destroy : function(){
255 Ext.destroy(this.more, this.moreMenu);
258 delete this.extrasTr;
259 Ext.layout.ToolbarLayout.superclass.destroy.call(this);
262 * @property activeItem
267 Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;
271 * @extends Ext.Container
272 * <p>Basic Toolbar class. Although the <tt>{@link Ext.Container#defaultType defaultType}</tt> for Toolbar
273 * is <tt>{@link Ext.Button button}</tt>, Toolbar elements (child items for the Toolbar container) may
274 * be virtually any type of Component. Toolbar elements can be created explicitly via their constructors,
275 * or implicitly via their xtypes, and can be <tt>{@link #add}</tt>ed dynamically.</p>
276 * <p>Some items have shortcut strings for creation:</p>
278 <u>Shortcut</u> <u>xtype</u> <u>Class</u> <u>Description</u>
279 '->' 'tbfill' {@link Ext.Toolbar.Fill} begin using the right-justified button container
280 '-' 'tbseparator' {@link Ext.Toolbar.Separator} add a vertical separator bar between toolbar items
281 ' ' 'tbspacer' {@link Ext.Toolbar.Spacer} add horiztonal space between elements
284 * Example usage of various elements:
286 var tb = new Ext.Toolbar({
287 renderTo: document.body,
292 // xtype: 'button', // default for Toolbars, same as 'tbbutton'
296 xtype: 'splitbutton', // same as 'tbsplitbutton'
299 // begin using the right-justified button container
300 '->', // same as {xtype: 'tbfill'}, // Ext.Toolbar.Fill
304 emptyText: 'enter search term'
306 // add a vertical separator bar between toolbar items
307 '-', // same as {xtype: 'tbseparator'} to create Ext.Toolbar.Separator
308 'text 1', // same as {xtype: 'tbtext', text: 'text1'} to create Ext.Toolbar.TextItem
309 {xtype: 'tbspacer'},// same as ' ' to create Ext.Toolbar.Spacer
311 {xtype: 'tbspacer', width: 50}, // add a 50px space
316 * Example adding a ComboBox within a menu of a button:
319 var combo = new Ext.form.ComboBox({
320 store: new Ext.data.ArrayStore({
322 fields: ['initials', 'fullname'],
324 ['FF', 'Fred Flintstone'],
325 ['BR', 'Barney Rubble']
328 displayField: 'fullname',
331 forceSelection: true,
332 triggerAction: 'all',
333 emptyText: 'Select a name...',
336 getListParent: function() {
337 return this.el.up('.x-menu');
339 iconCls: 'no-icon' //use iconCls if placing within menu to shift to right side of menu
342 // put ComboBox in a Menu
343 var menu = new Ext.menu.Menu({
346 combo // A Field in a Menu
350 // add a Button with the menu
352 text:'Button w/ Menu',
353 menu: menu // assign menu by instance
358 * Creates a new Toolbar
359 * @param {Object/Array} config A config object or an array of buttons to <tt>{@link #add}</tt>
362 Ext.Toolbar = function(config){
363 if(Ext.isArray(config)){
364 config = {items: config, layout: 'toolbar'};
370 config.items = config.buttons;
373 Ext.Toolbar.superclass.constructor.call(this, config);
380 Ext.extend(T, Ext.Container, {
382 defaultType: 'button',
385 * @cfg {String/Object} layout
386 * This class assigns a default layout (<code>layout:'<b>toolbar</b>'</code>).
387 * Developers <i>may</i> override this configuration option if another layout
388 * is required (the constructor must be passed a configuration object in this
389 * case instead of an array).
390 * See {@link Ext.Container#layout} for additional information.
393 * @cfg {Boolean} enableOverflow
394 * Defaults to false. Configure <code>true<code> to make the toolbar provide a button
395 * which activates a dropdown Menu to show items which overflow the Toolbar's width.
399 internalDefaults: {removeMode: 'container', hideParent: true},
400 toolbarCls: 'x-toolbar',
402 initComponent : function(){
403 T.superclass.initComponent.call(this);
406 * @event overflowchange
407 * Fires after the overflow state has changed.
408 * @param {Object} c The Container
409 * @param {Boolean} lastOverflow overflow state
411 this.addEvents('overflowchange');
415 onRender : function(ct, position){
417 if(!this.autoCreate){
419 cls: this.toolbarCls + ' x-small-editor'
422 this.el = ct.createChild(Ext.apply({ id: this.id },this.autoCreate), position);
423 Ext.Toolbar.superclass.onRender.apply(this, arguments);
428 * <p>Adds element(s) to the toolbar -- this function takes a variable number of
429 * arguments of mixed type and adds them to the toolbar.</p>
430 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
431 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
433 * <li>{@link Ext.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
434 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
435 * <li>Field: Any form field (equivalent to {@link #addField})</li>
436 * <li>Item: Any subclass of {@link Ext.Toolbar.Item} (equivalent to {@link #addItem})</li>
437 * <li>String: Any generic string (gets wrapped in a {@link Ext.Toolbar.TextItem}, equivalent to {@link #addText}).
438 * Note that there are a few special strings that are treated differently as explained next.</li>
439 * <li>'-': Creates a separator element (equivalent to {@link #addSeparator})</li>
440 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
441 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
443 * @param {Mixed} arg2
444 * @param {Mixed} etc.
449 lookupComponent : function(c){
452 c = new T.Separator();
458 c = new T.TextItem(c);
460 this.applyDefaults(c);
462 if(c.isFormField || c.render){ // some kind of form field, some kind of Toolbar.Item
463 c = this.createComponent(c);
464 }else if(c.tag){ // DomHelper spec
465 c = new T.Item({autoEl: c});
466 }else if(c.tagName){ // element
467 c = new T.Item({el:c});
468 }else if(Ext.isObject(c)){ // must be button config?
469 c = c.xtype ? this.createComponent(c) : this.constructButton(c);
476 applyDefaults : function(c){
477 if(!Ext.isString(c)){
478 c = Ext.Toolbar.superclass.applyDefaults.call(this, c);
479 var d = this.internalDefaults;
481 Ext.applyIf(c.initialConfig, d);
492 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
493 * @return {Ext.Toolbar.Item} The separator {@link Ext.Toolbar.Item item}
495 addSeparator : function(){
496 return this.add(new T.Separator());
500 * Adds a spacer element
501 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
502 * @return {Ext.Toolbar.Spacer} The spacer item
504 addSpacer : function(){
505 return this.add(new T.Spacer());
509 * Forces subsequent additions into the float:right toolbar
510 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
512 addFill : function(){
513 this.add(new T.Fill());
517 * Adds any standard HTML element to the toolbar
518 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
519 * @param {Mixed} el The element or id of the element to add
520 * @return {Ext.Toolbar.Item} The element's item
522 addElement : function(el){
523 return this.addItem(new T.Item({el:el}));
527 * Adds any Toolbar.Item or subclass
528 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
529 * @param {Ext.Toolbar.Item} item
530 * @return {Ext.Toolbar.Item} The item
532 addItem : function(item){
533 return this.add.apply(this, arguments);
537 * Adds a button (or buttons). See {@link Ext.Button} for more info on the config.
538 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
539 * @param {Object/Array} config A button config or array of configs
540 * @return {Ext.Button/Array}
542 addButton : function(config){
543 if(Ext.isArray(config)){
545 for(var i = 0, len = config.length; i < len; i++) {
546 buttons.push(this.addButton(config[i]));
550 return this.add(this.constructButton(config));
554 * Adds text to the toolbar
555 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
556 * @param {String} text The text to add
557 * @return {Ext.Toolbar.Item} The element's item
559 addText : function(text){
560 return this.addItem(new T.TextItem(text));
564 * Adds a new element to the toolbar from the passed {@link Ext.DomHelper} config
565 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
566 * @param {Object} config
567 * @return {Ext.Toolbar.Item} The element's item
569 addDom : function(config){
570 return this.add(new T.Item({autoEl: config}));
574 * Adds a dynamically rendered Ext.form field (TextField, ComboBox, etc). Note: the field should not have
575 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
576 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
577 * @param {Ext.form.Field} field
578 * @return {Ext.Toolbar.Item}
580 addField : function(field){
581 return this.add(field);
585 * Inserts any {@link Ext.Toolbar.Item}/{@link Ext.Button} at the specified index.
586 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
587 * @param {Number} index The index where the item is to be inserted
588 * @param {Object/Ext.Toolbar.Item/Ext.Button/Array} item The button, or button config object to be
589 * inserted, or an array of buttons/configs.
590 * @return {Ext.Button/Item}
592 insertButton : function(index, item){
593 if(Ext.isArray(item)){
595 for(var i = 0, len = item.length; i < len; i++) {
596 buttons.push(this.insertButton(index + i, item[i]));
600 return Ext.Toolbar.superclass.insert.call(this, index, item);
604 trackMenu : function(item, remove){
605 if(this.trackMenus && item.menu){
606 var method = remove ? 'mun' : 'mon';
607 this[method](item, 'menutriggerover', this.onButtonTriggerOver, this);
608 this[method](item, 'menushow', this.onButtonMenuShow, this);
609 this[method](item, 'menuhide', this.onButtonMenuHide, this);
614 constructButton : function(item){
615 var b = item.events ? item : this.createComponent(item, item.split ? 'splitbutton' : this.defaultType);
621 Ext.Toolbar.superclass.onAdd.call(this);
626 onRemove : function(c){
627 Ext.Toolbar.superclass.onRemove.call(this);
628 this.trackMenu(c, true);
632 onDisable : function(){
633 this.items.each(function(item){
641 onEnable : function(){
642 this.items.each(function(item){
650 onButtonTriggerOver : function(btn){
651 if(this.activeMenuBtn && this.activeMenuBtn != btn){
652 this.activeMenuBtn.hideMenu();
654 this.activeMenuBtn = btn;
659 onButtonMenuShow : function(btn){
660 this.activeMenuBtn = btn;
664 onButtonMenuHide : function(btn){
665 delete this.activeMenuBtn;
668 Ext.reg('toolbar', Ext.Toolbar);
671 * @class Ext.Toolbar.Item
672 * @extends Ext.BoxComponent
673 * The base class that other non-interacting Toolbar Item classes should extend in order to
674 * get some basic common toolbar item functionality.
677 * @param {HTMLElement} el
680 T.Item = Ext.extend(Ext.BoxComponent, {
681 hideParent: true, // Hiding a Toolbar.Item hides its containing TD
686 * @cfg {String} overflowText Text to be used for the menu if the item is overflowed.
689 Ext.reg('tbitem', T.Item);
692 * @class Ext.Toolbar.Separator
693 * @extends Ext.Toolbar.Item
694 * A simple class that adds a vertical separator bar between toolbar items
695 * (css class:<tt>'xtb-sep'</tt>). Example usage:
700 {xtype: 'tbseparator'}, // or '-'
706 * Creates a new Separator
709 T.Separator = Ext.extend(T.Item, {
710 onRender : function(ct, position){
711 this.el = ct.createChild({tag:'span', cls:'xtb-sep'}, position);
714 Ext.reg('tbseparator', T.Separator);
717 * @class Ext.Toolbar.Spacer
718 * @extends Ext.Toolbar.Item
719 * A simple element that adds extra horizontal space between items in a toolbar.
720 * By default a 2px wide space is added via css specification:<pre><code>
721 .x-toolbar .xtb-spacer {
725 * <p>Example usage:</p>
730 {xtype: 'tbspacer'}, // or ' '
732 // space width is also configurable via javascript
733 {xtype: 'tbspacer', width: 50}, // add a 50px space
739 * Creates a new Spacer
742 T.Spacer = Ext.extend(T.Item, {
744 * @cfg {Number} width
745 * The width of the spacer in pixels (defaults to 2px via css style <tt>.x-toolbar .xtb-spacer</tt>).
748 onRender : function(ct, position){
749 this.el = ct.createChild({tag:'div', cls:'xtb-spacer', style: this.width?'width:'+this.width+'px':''}, position);
752 Ext.reg('tbspacer', T.Spacer);
755 * @class Ext.Toolbar.Fill
756 * @extends Ext.Toolbar.Spacer
757 * A non-rendering placeholder item which instructs the Toolbar's Layout to begin using
758 * the right-justified button container.
763 {xtype: 'tbfill'}, // or '->'
772 T.Fill = Ext.extend(T.Item, {
774 render : Ext.emptyFn,
777 Ext.reg('tbfill', T.Fill);
780 * @class Ext.Toolbar.TextItem
781 * @extends Ext.Toolbar.Item
782 * A simple class that renders text directly into a toolbar
783 * (with css class:<tt>'xtb-text'</tt>). Example usage:
787 {xtype: 'tbtext', text: 'Item 1'} // or simply 'Item 1'
792 * Creates a new TextItem
793 * @param {String/Object} text A text string, or a config object containing a <tt>text</tt> property
796 T.TextItem = Ext.extend(T.Item, {
798 * @cfg {String} text The text to be used as innerHTML (html tags are accepted)
801 constructor: function(config){
802 T.TextItem.superclass.constructor.call(this, Ext.isString(config) ? {text: config} : config);
806 onRender : function(ct, position) {
807 this.autoEl = {cls: 'xtb-text', html: this.text || ''};
808 T.TextItem.superclass.onRender.call(this, ct, position);
812 * Updates this item's text, setting the text to be used as innerHTML.
813 * @param {String} t The text to display (html accepted).
815 setText : function(t) {
823 Ext.reg('tbtext', T.TextItem);
826 T.Button = Ext.extend(Ext.Button, {});
827 T.SplitButton = Ext.extend(Ext.SplitButton, {});
828 Ext.reg('tbbutton', T.Button);
829 Ext.reg('tbsplit', T.SplitButton);
833 * @class Ext.ButtonGroup
\r
834 * @extends Ext.Panel
\r
835 * Container for a group of buttons. Example usage:
\r
837 var p = new Ext.Panel({
\r
838 title: 'Panel with Button Group',
\r
841 renderTo: document.body,
\r
844 xtype: 'buttongroup',
\r
845 {@link #columns}: 3,
\r
846 title: 'Clipboard',
\r
850 rowspan: 3, iconCls: 'add',
\r
852 cls: 'x-btn-as-arrow'
\r
854 xtype:'splitbutton',
\r
855 text: 'Menu Button',
\r
860 arrowAlign:'bottom',
\r
861 menu: [{text: 'Menu Item 1'}]
\r
863 xtype:'splitbutton', text: 'Cut', iconCls: 'add16', menu: [{text: 'Cut Menu Item'}]
\r
865 text: 'Copy', iconCls: 'add16'
\r
867 text: 'Format', iconCls: 'add16'
\r
873 * Create a new ButtonGroup.
\r
874 * @param {Object} config The config object
\r
875 * @xtype buttongroup
\r
877 Ext.ButtonGroup = Ext.extend(Ext.Panel, {
\r
879 * @cfg {Number} columns The <tt>columns</tt> configuration property passed to the
\r
880 * {@link #layout configured layout manager}. See {@link Ext.layout.TableLayout#columns}.
\r
883 * @cfg {String} baseCls Defaults to <tt>'x-btn-group'</tt>. See {@link Ext.Panel#baseCls}.
\r
885 baseCls: 'x-btn-group',
\r
887 * @cfg {String} layout Defaults to <tt>'table'</tt>. See {@link Ext.Container#layout}.
\r
890 defaultType: 'button',
\r
892 * @cfg {Boolean} frame Defaults to <tt>true</tt>. See {@link Ext.Panel#frame}.
\r
895 internalDefaults: {removeMode: 'container', hideParent: true},
\r
897 initComponent : function(){
\r
898 this.layoutConfig = this.layoutConfig || {};
\r
899 Ext.applyIf(this.layoutConfig, {
\r
900 columns : this.columns
\r
903 this.addClass('x-btn-group-notitle');
\r
905 this.on('afterlayout', this.onAfterLayout, this);
\r
906 Ext.ButtonGroup.superclass.initComponent.call(this);
\r
909 applyDefaults : function(c){
\r
910 c = Ext.ButtonGroup.superclass.applyDefaults.call(this, c);
\r
911 var d = this.internalDefaults;
\r
913 Ext.applyIf(c.initialConfig, d);
\r
921 onAfterLayout : function(){
\r
922 var bodyWidth = this.body.getFrameWidth('lr') + this.body.dom.firstChild.offsetWidth;
\r
923 this.body.setWidth(bodyWidth);
\r
924 this.el.setWidth(bodyWidth + this.getFrameWidth());
\r
927 * @cfg {Array} tools @hide
\r
931 Ext.reg('buttongroup', Ext.ButtonGroup);
\r
933 * @class Ext.PagingToolbar
934 * @extends Ext.Toolbar
935 * <p>As the amount of records increases, the time required for the browser to render
936 * them increases. Paging is used to reduce the amount of data exchanged with the client.
937 * Note: if there are more records/rows than can be viewed in the available screen area, vertical
938 * scrollbars will be added.</p>
939 * <p>Paging is typically handled on the server side (see exception below). The client sends
940 * parameters to the server side, which the server needs to interpret and then respond with the
941 * approprate data.</p>
942 * <p><b>Ext.PagingToolbar</b> is a specialized toolbar that is bound to a {@link Ext.data.Store}
943 * and provides automatic paging control. This Component {@link Ext.data.Store#load load}s blocks
944 * of data into the <tt>{@link #store}</tt> by passing {@link Ext.data.Store#paramNames paramNames} used for
945 * paging criteria.</p>
946 * <p>PagingToolbar is typically used as one of the Grid's toolbars:</p>
948 Ext.QuickTips.init(); // to display button quicktips
950 var myStore = new Ext.data.Store({
951 reader: new Ext.data.JsonReader({
952 {@link Ext.data.JsonReader#totalProperty totalProperty}: 'results',
958 var myPageSize = 25; // server script should only send back 25 items at a time
960 var grid = new Ext.grid.GridPanel({
963 bbar: new Ext.PagingToolbar({
964 {@link #store}: myStore, // grid and PagingToolbar using same store
965 {@link #displayInfo}: true,
966 {@link #pageSize}: myPageSize,
967 {@link #prependButtons}: true,
975 * <p>To use paging, pass the paging requirements to the server when the store is first loaded.</p>
979 // specify params for the first page load if using paging
988 * <p>If using {@link Ext.data.Store#autoLoad store's autoLoad} configuration:</p>
990 var myStore = new Ext.data.Store({
991 {@link Ext.data.Store#autoLoad autoLoad}: {params:{start: 0, limit: 25}},
996 * <p>The packet sent back from the server would have this form:</p>
1001 "rows": [ // <b>*Note:</b> this must be an Array
1002 { "id": 1, "name": "Bill", "occupation": "Gardener" },
1003 { "id": 2, "name": "Ben", "occupation": "Horticulturalist" },
1005 { "id": 25, "name": "Sue", "occupation": "Botanist" }
1009 * <p><u>Paging with Local Data</u></p>
1010 * <p>Paging can also be accomplished with local data using extensions:</p>
1011 * <div class="mdetail-params"><ul>
1012 * <li><a href="http://extjs.com/forum/showthread.php?t=71532">Ext.ux.data.PagingStore</a></li>
1013 * <li>Paging Memory Proxy (examples/ux/PagingMemoryProxy.js)</li>
1015 * @constructor Create a new PagingToolbar
1016 * @param {Object} config The config object
1021 var T = Ext.Toolbar;
1023 Ext.PagingToolbar = Ext.extend(Ext.Toolbar, {
1025 * @cfg {Ext.data.Store} store
1026 * The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
1029 * @cfg {Boolean} displayInfo
1030 * <tt>true</tt> to display the displayMsg (defaults to <tt>false</tt>)
1033 * @cfg {Number} pageSize
1034 * The number of records to display per page (defaults to <tt>20</tt>)
1038 * @cfg {Boolean} prependButtons
1039 * <tt>true</tt> to insert any configured <tt>items</tt> <i>before</i> the paging buttons.
1040 * Defaults to <tt>false</tt>.
1043 * @cfg {String} displayMsg
1044 * The paging status message to display (defaults to <tt>'Displaying {0} - {1} of {2}'</tt>).
1045 * Note that this string is formatted using the braced numbers <tt>{0}-{2}</tt> as tokens
1046 * that are replaced by the values for start, end and total respectively. These tokens should
1047 * be preserved when overriding this string if showing those values is desired.
1049 displayMsg : 'Displaying {0} - {1} of {2}',
1051 * @cfg {String} emptyMsg
1052 * The message to display when no records are found (defaults to 'No data to display')
1054 emptyMsg : 'No data to display',
1056 * @cfg {String} beforePageText
1057 * The text displayed before the input item (defaults to <tt>'Page'</tt>).
1059 beforePageText : 'Page',
1061 * @cfg {String} afterPageText
1062 * Customizable piece of the default paging text (defaults to <tt>'of {0}'</tt>). Note that
1063 * this string is formatted using <tt>{0}</tt> as a token that is replaced by the number of
1064 * total pages. This token should be preserved when overriding this string if showing the
1065 * total page count is desired.
1067 afterPageText : 'of {0}',
1069 * @cfg {String} firstText
1070 * The quicktip text displayed for the first page button (defaults to <tt>'First Page'</tt>).
1071 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1073 firstText : 'First Page',
1075 * @cfg {String} prevText
1076 * The quicktip text displayed for the previous page button (defaults to <tt>'Previous Page'</tt>).
1077 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1079 prevText : 'Previous Page',
1081 * @cfg {String} nextText
1082 * The quicktip text displayed for the next page button (defaults to <tt>'Next Page'</tt>).
1083 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1085 nextText : 'Next Page',
1087 * @cfg {String} lastText
1088 * The quicktip text displayed for the last page button (defaults to <tt>'Last Page'</tt>).
1089 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1091 lastText : 'Last Page',
1093 * @cfg {String} refreshText
1094 * The quicktip text displayed for the Refresh button (defaults to <tt>'Refresh'</tt>).
1095 * <b>Note</b>: quick tips must be initialized for the quicktip to show.
1097 refreshText : 'Refresh',
1100 * <p><b>Deprecated</b>. <code>paramNames</code> should be set in the <b>data store</b>
1101 * (see {@link Ext.data.Store#paramNames}).</p>
1102 * <br><p>Object mapping of parameter names used for load calls, initially set to:</p>
1103 * <pre>{start: 'start', limit: 'limit'}</pre>
1105 * @property paramNames
1110 * The number of records to display per page. See also <tt>{@link #cursor}</tt>.
1112 * @property pageSize
1116 * Indicator for the record position. This property might be used to get the active page
1117 * number for example:<pre><code>
1118 * // t is reference to the paging toolbar instance
1119 * var activePage = Math.ceil((t.cursor + t.pageSize) / t.pageSize);
1125 initComponent : function(){
1126 var pagingItems = [this.first = new T.Button({
1127 tooltip: this.firstText,
1128 overflowText: this.firstText,
1129 iconCls: 'x-tbar-page-first',
1131 handler: this.moveFirst,
1133 }), this.prev = new T.Button({
1134 tooltip: this.prevText,
1135 overflowText: this.prevText,
1136 iconCls: 'x-tbar-page-prev',
1138 handler: this.movePrevious,
1140 }), '-', this.beforePageText,
1141 this.inputItem = new Ext.form.NumberField({
1142 cls: 'x-tbar-page-number',
1143 allowDecimals: false,
1144 allowNegative: false,
1145 enableKeyEvents: true,
1146 selectOnFocus: true,
1150 keydown: this.onPagingKeyDown,
1151 blur: this.onPagingBlur
1153 }), this.afterTextItem = new T.TextItem({
1154 text: String.format(this.afterPageText, 1)
1155 }), '-', this.next = new T.Button({
1156 tooltip: this.nextText,
1157 overflowText: this.nextText,
1158 iconCls: 'x-tbar-page-next',
1160 handler: this.moveNext,
1162 }), this.last = new T.Button({
1163 tooltip: this.lastText,
1164 overflowText: this.lastText,
1165 iconCls: 'x-tbar-page-last',
1167 handler: this.moveLast,
1169 }), '-', this.refresh = new T.Button({
1170 tooltip: this.refreshText,
1171 overflowText: this.refreshText,
1172 iconCls: 'x-tbar-loading',
1173 handler: this.doRefresh,
1178 var userItems = this.items || this.buttons || [];
1179 if (this.prependButtons) {
1180 this.items = userItems.concat(pagingItems);
1182 this.items = pagingItems.concat(userItems);
1184 delete this.buttons;
1185 if(this.displayInfo){
1186 this.items.push('->');
1187 this.items.push(this.displayItem = new T.TextItem({}));
1189 Ext.PagingToolbar.superclass.initComponent.call(this);
1193 * Fires after the active page has been changed.
1194 * @param {Ext.PagingToolbar} this
1195 * @param {Object} pageData An object that has these properties:<ul>
1196 * <li><code>total</code> : Number <div class="sub-desc">The total number of records in the dataset as
1197 * returned by the server</div></li>
1198 * <li><code>activePage</code> : Number <div class="sub-desc">The current page number</div></li>
1199 * <li><code>pages</code> : Number <div class="sub-desc">The total number of pages (calculated from
1200 * the total number of records in the dataset as returned by the server and the current {@link #pageSize})</div></li>
1205 * @event beforechange
1206 * Fires just before the active page is changed.
1207 * Return false to prevent the active page from being changed.
1208 * @param {Ext.PagingToolbar} this
1209 * @param {Object} params An object hash of the parameters which the PagingToolbar will send when
1210 * loading the required page. This will contain:<ul>
1211 * <li><code>start</code> : Number <div class="sub-desc">The starting row number for the next page of records to
1212 * be retrieved from the server</div></li>
1213 * <li><code>limit</code> : Number <div class="sub-desc">The number of records to be retrieved from the server</div></li>
1215 * <p>(note: the names of the <b>start</b> and <b>limit</b> properties are determined
1216 * by the store's {@link Ext.data.Store#paramNames paramNames} property.)</p>
1217 * <p>Parameters may be added as required in the event handler.</p>
1221 this.on('afterlayout', this.onFirstLayout, this, {single: true});
1223 this.bindStore(this.store, true);
1227 onFirstLayout : function(){
1229 this.onLoad.apply(this, this.dsLoaded);
1234 updateInfo : function(){
1235 if(this.displayItem){
1236 var count = this.store.getCount();
1237 var msg = count == 0 ?
1241 this.cursor+1, this.cursor+count, this.store.getTotalCount()
1243 this.displayItem.setText(msg);
1248 onLoad : function(store, r, o){
1250 this.dsLoaded = [store, r, o];
1253 var p = this.getParams();
1254 this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;
1255 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
1257 this.afterTextItem.setText(String.format(this.afterPageText, d.pages));
1258 this.inputItem.setValue(ap);
1259 this.first.setDisabled(ap == 1);
1260 this.prev.setDisabled(ap == 1);
1261 this.next.setDisabled(ap == ps);
1262 this.last.setDisabled(ap == ps);
1263 this.refresh.enable();
1265 this.fireEvent('change', this, d);
1269 getPageData : function(){
1270 var total = this.store.getTotalCount();
1273 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
1274 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
1279 * Change the active page
1280 * @param {Integer} page The page to display
1282 changePage : function(page){
1283 this.doLoad(((page-1) * this.pageSize).constrain(0, this.store.getTotalCount()));
1287 onLoadError : function(){
1291 this.refresh.enable();
1295 readPage : function(d){
1296 var v = this.inputItem.getValue(), pageNum;
1297 if (!v || isNaN(pageNum = parseInt(v, 10))) {
1298 this.inputItem.setValue(d.activePage);
1304 onPagingFocus : function(){
1305 this.inputItem.select();
1309 onPagingBlur : function(e){
1310 this.inputItem.setValue(this.getPageData().activePage);
1314 onPagingKeyDown : function(field, e){
1315 var k = e.getKey(), d = this.getPageData(), pageNum;
1316 if (k == e.RETURN) {
1318 pageNum = this.readPage(d);
1319 if(pageNum !== false){
1320 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
1321 this.doLoad(pageNum * this.pageSize);
1323 }else if (k == e.HOME || k == e.END){
1325 pageNum = k == e.HOME ? 1 : d.pages;
1326 field.setValue(pageNum);
1327 }else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){
1329 if((pageNum = this.readPage(d))){
1330 var increment = e.shiftKey ? 10 : 1;
1331 if(k == e.DOWN || k == e.PAGEDOWN){
1334 pageNum += increment;
1335 if(pageNum >= 1 & pageNum <= d.pages){
1336 field.setValue(pageNum);
1343 getParams : function(){
1344 //retain backwards compat, allow params on the toolbar itself, if they exist.
1345 return this.paramNames || this.store.paramNames;
1349 beforeLoad : function(){
1350 if(this.rendered && this.refresh){
1351 this.refresh.disable();
1356 doLoad : function(start){
1357 var o = {}, pn = this.getParams();
1358 o[pn.start] = start;
1359 o[pn.limit] = this.pageSize;
1360 if(this.fireEvent('beforechange', this, o) !== false){
1361 this.store.load({params:o});
1366 * Move to the first page, has the same effect as clicking the 'first' button.
1368 moveFirst : function(){
1373 * Move to the previous page, has the same effect as clicking the 'previous' button.
1375 movePrevious : function(){
1376 this.doLoad(Math.max(0, this.cursor-this.pageSize));
1380 * Move to the next page, has the same effect as clicking the 'next' button.
1382 moveNext : function(){
1383 this.doLoad(this.cursor+this.pageSize);
1387 * Move to the last page, has the same effect as clicking the 'last' button.
1389 moveLast : function(){
1390 var total = this.store.getTotalCount(),
1391 extra = total % this.pageSize;
1393 this.doLoad(extra ? (total - extra) : total - this.pageSize);
1397 * Refresh the current page, has the same effect as clicking the 'refresh' button.
1399 doRefresh : function(){
1400 this.doLoad(this.cursor);
1404 * Binds the paging toolbar to the specified {@link Ext.data.Store}
1405 * @param {Store} store The store to bind to this toolbar
1406 * @param {Boolean} initial (Optional) true to not remove listeners
1408 bindStore : function(store, initial){
1410 if(!initial && this.store){
1411 if(store !== this.store && this.store.autoDestroy){
1412 this.store.destroy();
1414 this.store.un('beforeload', this.beforeLoad, this);
1415 this.store.un('load', this.onLoad, this);
1416 this.store.un('exception', this.onLoadError, this);
1423 store = Ext.StoreMgr.lookup(store);
1426 beforeload: this.beforeLoad,
1428 exception: this.onLoadError
1434 this.onLoad(store, null, {});
1439 * Unbinds the paging toolbar from the specified {@link Ext.data.Store} <b>(deprecated)</b>
1440 * @param {Ext.data.Store} store The data store to unbind
1442 unbind : function(store){
1443 this.bindStore(null);
1447 * Binds the paging toolbar to the specified {@link Ext.data.Store} <b>(deprecated)</b>
1448 * @param {Ext.data.Store} store The data store to bind
1450 bind : function(store){
1451 this.bindStore(store);
1455 onDestroy : function(){
1456 this.bindStore(null);
1457 Ext.PagingToolbar.superclass.onDestroy.call(this);
1462 Ext.reg('paging', Ext.PagingToolbar);