3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.grid.GridPanel
10 * <p>This class represents the primary interface of a component based grid control to represent data
11 * in a tabular format of rows and columns. The GridPanel is composed of the following:</p>
12 * <div class="mdetail-params"><ul>
13 * <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows)
14 * <div class="sub-desc"></div></li>
15 * <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup
16 * <div class="sub-desc"></div></li>
17 * <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface
18 * <div class="sub-desc"></div></li>
19 * <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior
20 * <div class="sub-desc"></div></li>
22 * <p>Example usage:</p>
24 var grid = new Ext.grid.GridPanel({
25 {@link #store}: new {@link Ext.data.Store}({
26 {@link Ext.data.Store#autoDestroy autoDestroy}: true,
27 {@link Ext.data.Store#reader reader}: reader,
28 {@link Ext.data.Store#data data}: xg.dummyData
30 {@link #colModel}: new {@link Ext.grid.ColumnModel}({
31 {@link Ext.grid.ColumnModel#defaults defaults}: {
35 {@link Ext.grid.ColumnModel#columns columns}: [
36 {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
37 {header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
38 {header: 'Change', dataIndex: 'change'},
39 {header: '% Change', dataIndex: 'pctChange'},
40 // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
42 header: 'Last Updated', width: 135, dataIndex: 'lastChange',
43 xtype: 'datecolumn', format: 'M d, Y'
47 {@link #viewConfig}: {
48 {@link Ext.grid.GridView#forceFit forceFit}: true,
50 // Return CSS class to apply to rows depending upon data values
51 {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {
52 var c = record.{@link Ext.data.Record#get get}('change');
60 {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),
64 title: 'Framed with Row Selection and Horizontal Scrolling',
68 * <p><b><u>Notes:</u></b></p>
69 * <div class="mdetail-params"><ul>
70 * <li>Although this class inherits many configuration options from base classes, some of them
71 * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will
72 * have no effect.</li>
73 * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to
74 * scroll its rows. These dimensions can either be set explicitly through the
75 * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>
76 * configuration options or implicitly set by using the grid as a child item of a
77 * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}
78 * provide the sizing of its child items (for example the Container of the Grid may specify
79 * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>
80 * <li>To access the data in a Grid, it is necessary to use the data model encapsulated
81 * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>
84 * @param {Object} config The config object
87 Ext.grid.GridPanel = Ext.extend(Ext.Panel, {
89 * @cfg {String} autoExpandColumn
90 * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in
91 * this grid that should expand to fill unused space. This value specified here can not
93 * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with
94 * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>
95 * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>
96 * for additional details.</p>
97 * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>
99 autoExpandColumn : false,
102 * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
103 * can have (if enabled). Defaults to <tt>1000</tt>.
105 autoExpandMax : 1000,
108 * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
109 * can have (if enabled). Defaults to <tt>50</tt>.
114 * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
115 * Default is <tt>false</tt>.
120 * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
123 * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
126 * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
127 * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
128 * <tt>{@link #colModel}</tt> configuration property.
131 * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.
134 * @cfg {String} ddText
135 * Configures the text in the drag proxy. Defaults to:
137 * ddText : '{0} selected row{1}'
139 * <tt>{0}</tt> is replaced with the number of selected rows.
141 ddText : '{0} selected row{1}',
144 * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>
145 * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row
146 * structure deferred so that layouts with GridPanels appear more quickly.</p>
148 deferRowRender : true,
151 * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>
152 * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>
155 * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
158 * @cfg {Boolean} enableColumnHide
159 * Defaults to <tt>true</tt> to enable {@link Ext.grid.Column#hidden hiding of columns}
160 * with the {@link #enableHdMenu header menu}.
162 enableColumnHide : true,
165 * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>
166 * to turn off column reordering via drag drop.
168 enableColumnMove : true,
171 * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>
172 * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to
173 * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>
174 * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>
176 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of
177 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
178 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able
179 * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>
181 enableDragDrop : false,
184 * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
189 * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
192 * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
193 * loading. Defaults to <code>false</code>.
198 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
201 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
206 * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
209 * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide
210 * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).
213 * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
216 * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.
217 * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of
218 * the grid. A default CSS rule is provided which sets a background colour, but you can override this
219 * with a rule which either overrides the <b>background-color</b> style using the '!important'
220 * modifier, or which uses a CSS selector of higher specificity.</p>
225 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>
226 * for GridPanel, but <tt>false</tt> for EditorGridPanel.
228 trackMouseOver : true,
231 * @cfg {Array} stateEvents
232 * An array of events that, when fired, should trigger this component to save its state.
233 * Defaults to:<pre><code>
234 * stateEvents: ['columnmove', 'columnresize', 'sortchange', 'groupchange']
236 * <p>These can be any types of events supported by this component, including browser or
237 * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>
238 * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring
239 * Component state.</p>
241 stateEvents : ['columnmove', 'columnresize', 'sortchange', 'groupchange'],
244 * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set
245 * before a call to {@link Ext.Component#render render()}.
250 * @cfg {Array} bubbleEvents
251 * <p>An array of events that, when fired, should be bubbled to any parent container.
252 * See {@link Ext.util.Observable#enableBubble}.
253 * Defaults to <tt>[]</tt>.
258 * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of
259 * the config options available for {@link Ext.grid.GridView} can be specified here. This option
260 * is ignored if <tt>{@link #view}</tt> is specified.
270 initComponent : function() {
271 Ext.grid.GridPanel.superclass.initComponent.call(this);
273 if (this.columnLines) {
274 this.cls = (this.cls || '') + ' x-grid-with-col-lines';
276 // override any provided value since it isn't valid
277 // and is causing too many bug reports ;)
278 this.autoScroll = false;
279 this.autoWidth = false;
281 if(Ext.isArray(this.columns)){
282 this.colModel = new Ext.grid.ColumnModel(this.columns);
286 // check and correct shorthanded configs
288 this.store = this.ds;
292 this.colModel = this.cm;
296 this.selModel = this.sm;
299 this.store = Ext.StoreMgr.lookup(this.store);
305 * The raw click event for the entire grid.
306 * @param {Ext.EventObject} e
311 * The raw dblclick event for the entire grid.
312 * @param {Ext.EventObject} e
317 * The raw contextmenu event for the entire grid.
318 * @param {Ext.EventObject} e
323 * The raw mousedown event for the entire grid.
324 * @param {Ext.EventObject} e
329 * The raw mouseup event for the entire grid.
330 * @param {Ext.EventObject} e
335 * The raw mouseover event for the entire grid.
336 * @param {Ext.EventObject} e
341 * The raw mouseout event for the entire grid.
342 * @param {Ext.EventObject} e
347 * The raw keypress event for the entire grid.
348 * @param {Ext.EventObject} e
353 * The raw keydown event for the entire grid.
354 * @param {Ext.EventObject} e
360 * @event cellmousedown
361 * Fires before a cell is clicked
363 * @param {Number} rowIndex
364 * @param {Number} columnIndex
365 * @param {Ext.EventObject} e
369 * @event rowmousedown
370 * Fires before a row is clicked
372 * @param {Number} rowIndex
373 * @param {Ext.EventObject} e
377 * @event headermousedown
378 * Fires before a header is clicked
380 * @param {Number} columnIndex
381 * @param {Ext.EventObject} e
386 * @event groupmousedown
387 * Fires before a group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
389 * @param {String} groupField
390 * @param {String} groupValue
391 * @param {Ext.EventObject} e
396 * @event rowbodymousedown
397 * Fires before the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
399 * @param {Number} rowIndex
400 * @param {Ext.EventObject} e
405 * @event containermousedown
406 * Fires before the container is clicked. The container consists of any part of the grid body that is not covered by a row.
408 * @param {Ext.EventObject} e
410 'containermousedown',
414 * Fires when a cell is clicked.
415 * The data for the cell is drawn from the {@link Ext.data.Record Record}
416 * for this row. To access the data in the listener function use the
417 * following technique:
419 function(grid, rowIndex, columnIndex, e) {
420 var record = grid.getStore().getAt(rowIndex); // Get the Record
421 var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
422 var data = record.get(fieldName);
426 * @param {Number} rowIndex
427 * @param {Number} columnIndex
428 * @param {Ext.EventObject} e
432 * @event celldblclick
433 * Fires when a cell is double clicked
435 * @param {Number} rowIndex
436 * @param {Number} columnIndex
437 * @param {Ext.EventObject} e
442 * Fires when a row is clicked
444 * @param {Number} rowIndex
445 * @param {Ext.EventObject} e
450 * Fires when a row is double clicked
452 * @param {Number} rowIndex
453 * @param {Ext.EventObject} e
458 * Fires when a header is clicked
460 * @param {Number} columnIndex
461 * @param {Ext.EventObject} e
465 * @event headerdblclick
466 * Fires when a header cell is double clicked
468 * @param {Number} columnIndex
469 * @param {Ext.EventObject} e
474 * Fires when group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
476 * @param {String} groupField
477 * @param {String} groupValue
478 * @param {Ext.EventObject} e
482 * @event groupdblclick
483 * Fires when group header is double clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
485 * @param {String} groupField
486 * @param {String} groupValue
487 * @param {Ext.EventObject} e
491 * @event containerclick
492 * Fires when the container is clicked. The container consists of any part of the grid body that is not covered by a row.
494 * @param {Ext.EventObject} e
498 * @event containerdblclick
499 * Fires when the container is double clicked. The container consists of any part of the grid body that is not covered by a row.
501 * @param {Ext.EventObject} e
506 * @event rowbodyclick
507 * Fires when the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
509 * @param {Number} rowIndex
510 * @param {Ext.EventObject} e
514 * @event rowbodydblclick
515 * Fires when the row body is double clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
517 * @param {Number} rowIndex
518 * @param {Ext.EventObject} e
523 * @event rowcontextmenu
524 * Fires when a row is right clicked
526 * @param {Number} rowIndex
527 * @param {Ext.EventObject} e
531 * @event cellcontextmenu
532 * Fires when a cell is right clicked
534 * @param {Number} rowIndex
535 * @param {Number} cellIndex
536 * @param {Ext.EventObject} e
540 * @event headercontextmenu
541 * Fires when a header is right clicked
543 * @param {Number} columnIndex
544 * @param {Ext.EventObject} e
548 * @event groupcontextmenu
549 * Fires when group header is right clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
551 * @param {String} groupField
552 * @param {String} groupValue
553 * @param {Ext.EventObject} e
557 * @event containercontextmenu
558 * Fires when the container is right clicked. The container consists of any part of the grid body that is not covered by a row.
560 * @param {Ext.EventObject} e
562 'containercontextmenu',
564 * @event rowbodycontextmenu
565 * Fires when the row body is right clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
567 * @param {Number} rowIndex
568 * @param {Ext.EventObject} e
570 'rowbodycontextmenu',
573 * Fires when the body element is scrolled
574 * @param {Number} scrollLeft
575 * @param {Number} scrollTop
579 * @event columnresize
580 * Fires when the user resizes a column
581 * @param {Number} columnIndex
582 * @param {Number} newSize
587 * Fires when the user moves a column
588 * @param {Number} oldIndex
589 * @param {Number} newIndex
594 * Fires when the grid's store sort changes
596 * @param {Object} sortInfo An object with the keys field and direction
601 * Fires when the grid's grouping changes (only applies for grids with a {@link Ext.grid.GroupingView GroupingView})
603 * @param {String} groupField A string with the grouping field, null if the store is not grouped.
608 * Fires when the grid is reconfigured with a new store and/or column model.
610 * @param {Ext.data.Store} store The new store
611 * @param {Ext.grid.ColumnModel} colModel The new column model
616 * Fires when the grid view is available (use this for selecting a default row).
624 onRender : function(ct, position){
625 Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
627 var c = this.getGridEl();
629 this.el.addClass('x-grid-panel');
633 mousedown: this.onMouseDown,
635 dblclick: this.onDblClick,
636 contextmenu: this.onContextMenu
639 this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress', 'keydown']);
641 var view = this.getView();
644 this.getSelectionModel().init(this);
648 initEvents : function(){
649 Ext.grid.GridPanel.superclass.initEvents.call(this);
652 this.loadMask = new Ext.LoadMask(this.bwrap,
653 Ext.apply({store:this.store}, this.loadMask));
657 initStateEvents : function(){
658 Ext.grid.GridPanel.superclass.initStateEvents.call(this);
659 this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
662 applyState : function(state){
663 var cm = this.colModel,
671 for(var i = 0, len = cs.length; i < len; i++){
673 c = cm.getColumnById(s.id);
679 oldIndex = cm.getIndexById(s.id);
681 cm.moveColumn(oldIndex, i);
689 store[store.remoteSort ? 'setDefaultSort' : 'sort'](s.field, s.direction);
696 store.clearGrouping();
701 var o = Ext.apply({}, state);
704 Ext.grid.GridPanel.superclass.applyState.call(this, o);
707 getState : function(){
708 var o = {columns: []},
713 for(var i = 0, c; (c = this.colModel.config[i]); i++){
719 o.columns[i].hidden = true;
723 ss = store.getSortState();
727 if(store.getGroupState){
728 gs = store.getGroupState();
738 afterRender : function(){
739 Ext.grid.GridPanel.superclass.afterRender.call(this);
741 this.on('bodyresize', v.layout, v);
743 if(this.deferRowRender){
744 if (!this.deferRowRenderTask){
745 this.deferRowRenderTask = new Ext.util.DelayedTask(v.afterRender, this.view);
747 this.deferRowRenderTask.delay(10);
751 this.viewReady = true;
755 * <p>Reconfigures the grid to use a different Store and Column Model
756 * and fires the 'reconfigure' event. The View will be bound to the new
757 * objects and refreshed.</p>
758 * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
759 * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
760 * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
761 * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
762 * with the new data.</p>
763 * @param {Ext.data.Store} store The new {@link Ext.data.Store} object
764 * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
766 reconfigure : function(store, colModel){
767 var rendered = this.rendered;
770 this.loadMask.destroy();
771 this.loadMask = new Ext.LoadMask(this.bwrap,
772 Ext.apply({}, {store:store}, this.initialConfig.loadMask));
776 this.view.initData(store, colModel);
779 this.colModel = colModel;
781 this.view.refresh(true);
783 this.fireEvent('reconfigure', this, store, colModel);
787 onDestroy : function(){
788 if (this.deferRowRenderTask && this.deferRowRenderTask.cancel){
789 this.deferRowRenderTask.cancel();
792 Ext.destroy(this.view, this.loadMask);
793 }else if(this.store && this.store.autoDestroy){
794 this.store.destroy();
796 Ext.destroy(this.colModel, this.selModel);
797 this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
798 Ext.grid.GridPanel.superclass.onDestroy.call(this);
802 processEvent : function(name, e){
803 this.view.processEvent(name, e);
807 onClick : function(e){
808 this.processEvent('click', e);
812 onMouseDown : function(e){
813 this.processEvent('mousedown', e);
817 onContextMenu : function(e, t){
818 this.processEvent('contextmenu', e);
822 onDblClick : function(e){
823 this.processEvent('dblclick', e);
827 walkCells : function(row, col, step, fn, scope){
828 var cm = this.colModel,
829 clen = cm.getColumnCount(),
831 rlen = ds.getCount(),
845 if(fn.call(scope || this, row, col, cm) === true){
863 if(fn.call(scope || this, row, col, cm) === true){
875 * Returns the grid's underlying element.
876 * @return {Element} The element
878 getGridEl : function(){
882 // private for compatibility, overridden by editor grid
883 stopEditing : Ext.emptyFn,
886 * Returns the grid's selection model configured by the <code>{@link #selModel}</code>
887 * configuration option. If no selection model was configured, this will create
888 * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
889 * @return {SelectionModel}
891 getSelectionModel : function(){
893 this.selModel = new Ext.grid.RowSelectionModel(
894 this.disableSelection ? {selectRow: Ext.emptyFn} : null);
896 return this.selModel;
900 * Returns the grid's data store.
901 * @return {Ext.data.Store} The store
903 getStore : function(){
908 * Returns the grid's ColumnModel.
909 * @return {Ext.grid.ColumnModel} The column model
911 getColumnModel : function(){
912 return this.colModel;
916 * Returns the grid's GridView object.
917 * @return {Ext.grid.GridView} The grid view
919 getView : function() {
921 this.view = new Ext.grid.GridView(this.viewConfig);
927 * Called to get grid's drag proxy text, by default returns this.ddText.
928 * @return {String} The text
930 getDragDropText : function(){
931 var count = this.selModel.getCount();
932 return String.format(this.ddText, count, count == 1 ? '' : 's');
936 * @cfg {String/Number} activeItem
940 * @cfg {Boolean} autoDestroy
944 * @cfg {Object/String/Function} autoLoad
948 * @cfg {Boolean} autoWidth
952 * @cfg {Boolean/Number} bufferResize
956 * @cfg {String} defaultType
960 * @cfg {Object} defaults
964 * @cfg {Boolean} hideBorders
972 * @cfg {String} layout
976 * @cfg {Object} layoutConfig
980 * @cfg {Boolean} monitorResize
1012 * @method findByType
1016 * @method getComponent
1024 * @method getUpdater
1044 * @event afterlayout
1052 * @event beforeremove
1063 * @cfg {String} allowDomMove @hide
1066 * @cfg {String} autoEl @hide
1069 * @cfg {String} applyTo @hide
1072 * @cfg {String} autoScroll @hide
1075 * @cfg {String} bodyBorder @hide
1078 * @cfg {String} bodyStyle @hide
1081 * @cfg {String} contentEl @hide
1084 * @cfg {String} disabledClass @hide
1087 * @cfg {String} elements @hide
1090 * @cfg {String} html @hide
1093 * @cfg {Boolean} preventBodyReset
1097 * @property disabled
1101 * @method applyToMarkup
1113 * @method setDisabled
1117 Ext.reg('grid', Ext.grid.GridPanel);/**
1118 * @class Ext.grid.PivotGrid
1119 * @extends Ext.grid.GridPanel
1120 * <p>The PivotGrid component enables rapid summarization of large data sets. It provides a way to reduce a large set of
1121 * data down into a format where trends and insights become more apparent. A classic example is in sales data; a company
1122 * will often have a record of all sales it makes for a given period - this will often encompass thousands of rows of
1123 * data. The PivotGrid allows you to see how well each salesperson performed, which cities generate the most revenue,
1124 * how products perform between cities and so on.</p>
1125 * <p>A PivotGrid is composed of two axes (left and top), one {@link #measure} and one {@link #aggregator aggregation}
1126 * function. Each axis can contain one or more {@link #dimension}, which are ordered into a hierarchy. Dimensions on the
1127 * left axis can also specify a width. Each dimension in each axis can specify its sort ordering, defaulting to "ASC",
1128 * and must specify one of the fields in the {@link Ext.data.Record Record} used by the PivotGrid's
1129 * {@link Ext.data.Store Store}.</p>
1131 // This is the record representing a single sale
1132 var SaleRecord = Ext.data.Record.create([
1133 {name: 'person', type: 'string'},
1134 {name: 'product', type: 'string'},
1135 {name: 'city', type: 'string'},
1136 {name: 'state', type: 'string'},
1137 {name: 'year', type: 'int'},
1138 {name: 'value', type: 'int'}
1141 // A simple store that loads SaleRecord data from a url
1142 var myStore = new Ext.data.Store({
1145 reader: new Ext.data.JsonReader({
1151 // Create the PivotGrid itself, referencing the store
1152 var pivot = new Ext.grid.PivotGrid({
1160 dataIndex: 'product'
1164 dataIndex: 'person',
1176 * <p>The specified {@link #measure} is the field from SaleRecord that is extracted from each combination
1177 * of product and person (on the left axis) and year on the top axis. There may be several SaleRecords in the
1178 * data set that share this combination, so an array of measure fields is produced. This array is then
1179 * aggregated using the {@link #aggregator} function.</p>
1180 * <p>The default aggregator function is sum, which simply adds up all of the extracted measure values. Other
1181 * built-in aggregator functions are count, avg, min and max. In addition, you can specify your own function.
1182 * In this example we show the code used to sum the measures, but you can return any value you like. See
1183 * {@link #aggregator} for more details.</p>
1185 new Ext.grid.PivotGrid({
1186 aggregator: function(records, measure) {
1187 var length = records.length,
1191 for (i = 0; i < length; i++) {
1192 total += records[i].get(measure);
1198 renderer: function(value) {
1199 return Math.round(value);
1202 //your normal config here
1205 * <p><u>Renderers</u></p>
1206 * <p>PivotGrid optionally accepts a {@link #renderer} function which can modify the data in each cell before it
1207 * is rendered. The renderer is passed the value that would usually be placed in the cell and is expected to return
1208 * the new value. For example let's imagine we had height data expressed as a decimal - here's how we might use a
1209 * renderer to display the data in feet and inches notation:</p>
1211 new Ext.grid.PivotGrid({
1212 //in each case the value is a decimal number of feet
1213 renderer : function(value) {
1214 var feet = Math.floor(value),
1215 inches = Math.round((value - feet) * 12);
1217 return String.format("{0}' {1}\"", feet, inches);
1219 //normal config here
1222 * <p><u>Reconfiguring</u></p>
1223 * <p>All aspects PivotGrid's configuration can be updated at runtime. It is easy to change the {@link #setMeasure measure},
1224 * {@link #setAggregator aggregation function}, {@link #setLeftAxis left} and {@link #setTopAxis top} axes and refresh the grid.</p>
1225 * <p>In this case we reconfigure the PivotGrid to have city and year as the top axis dimensions, rendering the average sale
1226 * value into the cells:</p>
1228 //the left axis can also be changed
1229 pivot.topAxis.setDimensions([
1230 {dataIndex: 'city', direction: 'DESC'},
1231 {dataIndex: 'year', direction: 'ASC'}
1234 pivot.setMeasure('value');
1235 pivot.setAggregator('avg');
1237 pivot.view.refresh(true);
1239 * <p>See the {@link Ext.grid.PivotAxis PivotAxis} documentation for further detail on reconfiguring axes.</p>
1241 Ext.grid.PivotGrid = Ext.extend(Ext.grid.GridPanel, {
1244 * @cfg {String|Function} aggregator The aggregation function to use to combine the measures extracted
1245 * for each dimension combination. Can be any of the built-in aggregators (sum, count, avg, min, max).
1246 * Can also be a function which accepts two arguments (an array of Records to aggregate, and the measure
1247 * to aggregate them on) and should return a String.
1252 * @cfg {Function} renderer Optional renderer to pass values through before they are rendered to the dom. This
1253 * gives an opportunity to modify cell contents after the value has been computed.
1255 renderer: undefined,
1258 * @cfg {String} measure The field to extract from each Record when pivoting around the two axes. See the class
1259 * introduction docs for usage
1263 * @cfg {Array|Ext.grid.PivotAxis} leftAxis Either and array of {@link #dimension} to use on the left axis, or
1264 * a {@link Ext.grid.PivotAxis} instance. If an array is passed, it is turned into a PivotAxis internally.
1268 * @cfg {Array|Ext.grid.PivotAxis} topAxis Either and array of {@link #dimension} to use on the top axis, or
1269 * a {@link Ext.grid.PivotAxis} instance. If an array is passed, it is turned into a PivotAxis internally.
1273 initComponent: function() {
1274 Ext.grid.PivotGrid.superclass.initComponent.apply(this, arguments);
1278 //no resizing of columns is allowed yet in PivotGrid
1279 this.enableColumnResize = false;
1281 this.viewConfig = Ext.apply(this.viewConfig || {}, {
1285 //TODO: dummy col model that is never used - GridView is too tightly integrated with ColumnModel
1286 //in 3.x to remove this altogether.
1287 this.colModel = new Ext.grid.ColumnModel({});
1291 * Returns the function currently used to aggregate the records in each Pivot cell
1292 * @return {Function} The current aggregator function
1294 getAggregator: function() {
1295 if (typeof this.aggregator == 'string') {
1296 return Ext.grid.PivotAggregatorMgr.types[this.aggregator];
1298 return this.aggregator;
1303 * Sets the function to use when aggregating data for each cell.
1304 * @param {String|Function} aggregator The new aggregator function or named function string
1306 setAggregator: function(aggregator) {
1307 this.aggregator = aggregator;
1311 * Sets the field name to use as the Measure in this Pivot Grid
1312 * @param {String} measure The field to make the measure
1314 setMeasure: function(measure) {
1315 this.measure = measure;
1319 * Sets the left axis of this pivot grid. Optionally refreshes the grid afterwards.
1320 * @param {Ext.grid.PivotAxis} axis The pivot axis
1321 * @param {Boolean} refresh True to immediately refresh the grid and its axes (defaults to false)
1323 setLeftAxis: function(axis, refresh) {
1325 * The configured {@link Ext.grid.PivotAxis} used as the left Axis for this Pivot Grid
1326 * @property leftAxis
1327 * @type Ext.grid.PivotAxis
1329 this.leftAxis = axis;
1332 this.view.refresh();
1337 * Sets the top axis of this pivot grid. Optionally refreshes the grid afterwards.
1338 * @param {Ext.grid.PivotAxis} axis The pivot axis
1339 * @param {Boolean} refresh True to immediately refresh the grid and its axes (defaults to false)
1341 setTopAxis: function(axis, refresh) {
1343 * The configured {@link Ext.grid.PivotAxis} used as the top Axis for this Pivot Grid
1345 * @type Ext.grid.PivotAxis
1347 this.topAxis = axis;
1350 this.view.refresh();
1356 * Creates the top and left axes. Should usually only need to be called once from initComponent
1358 initAxes: function() {
1359 var PivotAxis = Ext.grid.PivotAxis;
1361 if (!(this.leftAxis instanceof PivotAxis)) {
1362 this.setLeftAxis(new PivotAxis({
1363 orientation: 'vertical',
1364 dimensions : this.leftAxis || [],
1369 if (!(this.topAxis instanceof PivotAxis)) {
1370 this.setTopAxis(new PivotAxis({
1371 orientation: 'horizontal',
1372 dimensions : this.topAxis || [],
1380 * @return {Array} 2-dimensional array of cell data
1382 extractData: function() {
1383 var records = this.store.data.items,
1384 recCount = records.length,
1388 if (recCount == 0) {
1392 var leftTuples = this.leftAxis.getTuples(),
1393 leftCount = leftTuples.length,
1394 topTuples = this.topAxis.getTuples(),
1395 topCount = topTuples.length,
1396 aggregator = this.getAggregator();
1398 for (i = 0; i < recCount; i++) {
1399 record = records[i];
1401 for (j = 0; j < leftCount; j++) {
1402 cells[j] = cells[j] || [];
1404 if (leftTuples[j].matcher(record) === true) {
1405 for (k = 0; k < topCount; k++) {
1406 cells[j][k] = cells[j][k] || [];
1408 if (topTuples[k].matcher(record)) {
1409 cells[j][k].push(record);
1416 var rowCount = cells.length,
1419 for (i = 0; i < rowCount; i++) {
1421 colCount = row.length;
1423 for (j = 0; j < colCount; j++) {
1424 cells[i][j] = aggregator(cells[i][j], this.measure);
1432 * Returns the grid's GridView object.
1433 * @return {Ext.grid.PivotGridView} The grid view
1435 getView: function() {
1437 this.view = new Ext.grid.PivotGridView(this.viewConfig);
1444 Ext.reg('pivotgrid', Ext.grid.PivotGrid);
1447 Ext.grid.PivotAggregatorMgr = new Ext.AbstractManager();
1449 Ext.grid.PivotAggregatorMgr.registerType('sum', function(records, measure) {
1450 var length = records.length,
1454 for (i = 0; i < length; i++) {
1455 total += records[i].get(measure);
1461 Ext.grid.PivotAggregatorMgr.registerType('avg', function(records, measure) {
1462 var length = records.length,
1466 for (i = 0; i < length; i++) {
1467 total += records[i].get(measure);
1470 return (total / length) || 'n/a';
1473 Ext.grid.PivotAggregatorMgr.registerType('min', function(records, measure) {
1475 length = records.length,
1478 for (i = 0; i < length; i++) {
1479 data.push(records[i].get(measure));
1482 return Math.min.apply(this, data) || 'n/a';
1485 Ext.grid.PivotAggregatorMgr.registerType('max', function(records, measure) {
1487 length = records.length,
1490 for (i = 0; i < length; i++) {
1491 data.push(records[i].get(measure));
1494 return Math.max.apply(this, data) || 'n/a';
1497 Ext.grid.PivotAggregatorMgr.registerType('count', function(records, measure) {
1498 return records.length;
1500 * @class Ext.grid.GridView
1501 * @extends Ext.util.Observable
1502 * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
1503 * Methods of this class may be used to access user interface elements to enable
1504 * special display effects. Do not change the DOM structure of the user interface.</p>
1505 * <p>This class does not provide ways to manipulate the underlying data. The data
1506 * model of a Grid is held in an {@link Ext.data.Store}.</p>
1508 * @param {Object} config
1510 Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
1512 * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
1513 * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
1514 * parameter. This function should return the CSS class name (or empty string '' for none) that will be added
1515 * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
1516 * (e.g., 'my-class another-class'). Example usage:
1520 showPreview: true, // custom property
1521 enableRowBody: true, // required to create a second, full-width row to show expanded Record data
1522 getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
1523 if(this.showPreview){
1524 rp.body = '<p>'+record.data.excerpt+'</p>';
1525 return 'x-grid3-row-expanded';
1527 return 'x-grid3-row-collapsed';
1531 * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
1532 * @param {Number} index The row index.
1533 * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
1534 * customization of various aspects of a grid row.
1535 * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
1536 * by this function, and will be used to render a full-width expansion row below each grid row:</p>
1538 * <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be used as the expansion row's body content (defaults to '').</div></li>
1539 * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's <tr> element. (defaults to '').</div></li>
1541 * The following property will be passed in, and may be appended to:
1543 * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates
1544 * both the standard grid row, and any expansion row.</div></li>
1546 * @param {Store} store The {@link Ext.data.Store} this grid is bound to
1547 * @method getRowClass
1548 * @return {String} a CSS class name to add to the row.
1552 * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
1553 * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
1557 * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
1558 * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
1560 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1565 * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
1566 * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
1567 * config to disable the <i>menu</i> for individual columns. While this config is true the
1568 * following will be disabled:<div class="mdetail-params"><ul>
1569 * <li>clicking on header to sort</li>
1570 * <li>the trigger to reveal the menu.</li>
1575 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
1576 * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
1577 * See {@link Ext.grid.GridDragZone} for details.</p>
1578 * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>
1579 * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>
1580 * <li><i>after</i> the owning GridPanel has been rendered.</li>
1582 * @property dragZone
1583 * @type {Ext.grid.GridDragZone}
1587 * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
1588 * first load (defaults to <tt>true</tt>).
1590 deferEmptyText : true,
1593 * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
1594 * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
1597 scrollOffset : undefined,
1600 * @cfg {Boolean} autoFill
1601 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1602 * when the grid is <b>initially rendered</b>. The
1603 * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
1604 * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
1605 * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
1606 * See <tt>{@link #forceFit}</tt> also.
1611 * @cfg {Boolean} forceFit
1612 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1613 * at <b>all times</b>. The {@link Ext.grid.Column#width initially configured width}</tt> of each
1614 * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are
1615 * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized
1616 * to fit the grid width. See <tt>{@link #autoFill}</tt> also.
1621 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
1623 sortClasses : ['sort-asc', 'sort-desc'],
1626 * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
1628 sortAscText : 'Sort Ascending',
1631 * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
1633 sortDescText : 'Sort Descending',
1636 * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>)
1638 columnsText : 'Columns',
1641 * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An
1642 * example overriding the default styling:
1644 .x-grid3-row-selected {background-color: yellow;}
1646 * Note that this only controls the row, and will not do anything for the text inside it. To style inner
1647 * facets (like text) use something like:
1649 .x-grid3-row-selected .x-grid3-cell-inner {
1655 selectedRowClass : 'x-grid3-row-selected',
1659 tdClass : 'x-grid3-cell',
1660 hdCls : 'x-grid3-hd',
1664 * @cfg {Boolean} markDirty True to show the dirty cell indicator when a cell has been modified. Defaults to <tt>true</tt>.
1669 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
1671 cellSelectorDepth : 4,
1674 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
1676 rowSelectorDepth : 10,
1679 * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
1681 rowBodySelectorDepth : 10,
1684 * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
1686 cellSelector : 'td.x-grid3-cell',
1689 * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
1691 rowSelector : 'div.x-grid3-row',
1694 * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
1696 rowBodySelector : 'div.x-grid3-row-body',
1699 firstRowCls: 'x-grid3-row-first',
1700 lastRowCls: 'x-grid3-row-last',
1701 rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
1704 * @cfg {String} headerMenuOpenCls The CSS class to add to the header cell when its menu is visible. Defaults to 'x-grid3-hd-menu-open'
1706 headerMenuOpenCls: 'x-grid3-hd-menu-open',
1709 * @cfg {String} rowOverCls The CSS class added to each row when it is hovered over. Defaults to 'x-grid3-row-over'
1711 rowOverCls: 'x-grid3-row-over',
1713 constructor : function(config) {
1714 Ext.apply(this, config);
1716 // These events are only used internally by the grid components
1719 * @event beforerowremoved
1720 * Internal UI Event. Fired before a row is removed.
1721 * @param {Ext.grid.GridView} view
1722 * @param {Number} rowIndex The index of the row to be removed.
1723 * @param {Ext.data.Record} record The Record to be removed
1728 * @event beforerowsinserted
1729 * Internal UI Event. Fired before rows are inserted.
1730 * @param {Ext.grid.GridView} view
1731 * @param {Number} firstRow The index of the first row to be inserted.
1732 * @param {Number} lastRow The index of the last row to be inserted.
1734 'beforerowsinserted',
1737 * @event beforerefresh
1738 * Internal UI Event. Fired before the view is refreshed.
1739 * @param {Ext.grid.GridView} view
1745 * Internal UI Event. Fired after a row is removed.
1746 * @param {Ext.grid.GridView} view
1747 * @param {Number} rowIndex The index of the row that was removed.
1748 * @param {Ext.data.Record} record The Record that was removed
1753 * @event rowsinserted
1754 * Internal UI Event. Fired after rows are inserted.
1755 * @param {Ext.grid.GridView} view
1756 * @param {Number} firstRow The index of the first inserted.
1757 * @param {Number} lastRow The index of the last row inserted.
1763 * Internal UI Event. Fired after a row has been updated.
1764 * @param {Ext.grid.GridView} view
1765 * @param {Number} firstRow The index of the row updated.
1766 * @param {Ext.data.record} record The Record backing the row updated.
1772 * Internal UI Event. Fired after the GridView's body has been refreshed.
1773 * @param {Ext.grid.GridView} view
1778 Ext.grid.GridView.superclass.constructor.call(this);
1781 /* -------------------------------- UI Specific ----------------------------- */
1784 * The master template to use when rendering the GridView. Has a default template
1785 * @property Ext.Template
1788 masterTpl: new Ext.Template(
1789 '<div class="x-grid3" hidefocus="true">',
1790 '<div class="x-grid3-viewport">',
1791 '<div class="x-grid3-header">',
1792 '<div class="x-grid3-header-inner">',
1793 '<div class="x-grid3-header-offset" style="{ostyle}">{header}</div>',
1795 '<div class="x-clear"></div>',
1797 '<div class="x-grid3-scroller">',
1798 '<div class="x-grid3-body" style="{bstyle}">{body}</div>',
1799 '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
1802 '<div class="x-grid3-resize-marker"> </div>',
1803 '<div class="x-grid3-resize-proxy"> </div>',
1808 * The template to use when rendering headers. Has a default template
1809 * @property headerTpl
1810 * @type Ext.Template
1812 headerTpl: new Ext.Template(
1813 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1815 '<tr class="x-grid3-hd-row">{cells}</tr>',
1821 * The template to use when rendering the body. Has a default template
1823 * @type Ext.Template
1825 bodyTpl: new Ext.Template('{rows}'),
1828 * The template to use to render each cell. Has a default template
1830 * @type Ext.Template
1832 cellTpl: new Ext.Template(
1833 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
1834 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
1840 * Provides default templates if they are not given for this particular instance. Most of the templates are defined on
1841 * the prototype, the ones defined inside this function are done so because they are based on Grid or GridView configuration
1843 initTemplates : function() {
1844 var templates = this.templates || {},
1847 headerCellTpl = new Ext.Template(
1848 '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
1849 '<div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
1850 this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
1852 '<img alt="" class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
1858 '<tr class="x-grid3-row-body-tr" style="{bodyStyle}">',
1859 '<td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on">',
1860 '<div class="x-grid3-row-body">{body}</div>',
1866 '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1869 this.enableRowBody ? rowBodyText : '',
1874 Ext.applyIf(templates, {
1875 hcell : headerCellTpl,
1876 cell : this.cellTpl,
1877 body : this.bodyTpl,
1878 header : this.headerTpl,
1879 master : this.masterTpl,
1880 row : new Ext.Template('<div class="x-grid3-row {alt}" style="{tstyle}">' + innerText + '</div>'),
1881 rowInner: new Ext.Template(innerText)
1884 for (name in templates) {
1885 template = templates[name];
1887 if (template && Ext.isFunction(template.compile) && !template.compiled) {
1888 template.disableFormats = true;
1893 this.templates = templates;
1894 this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
1899 * Each GridView has its own private flyweight, accessed through this method
1901 fly : function(el) {
1902 if (!this._flyweight) {
1903 this._flyweight = new Ext.Element.Flyweight(document.body);
1905 this._flyweight.dom = el;
1906 return this._flyweight;
1910 getEditorParent : function() {
1911 return this.scroller.dom;
1916 * Finds and stores references to important elements
1918 initElements : function() {
1919 var Element = Ext.Element,
1920 el = Ext.get(this.grid.getGridEl().dom.firstChild),
1921 mainWrap = new Element(el.child('div.x-grid3-viewport')),
1922 mainHd = new Element(mainWrap.child('div.x-grid3-header')),
1923 scroller = new Element(mainWrap.child('div.x-grid3-scroller'));
1925 if (this.grid.hideHeaders) {
1926 mainHd.setDisplayed(false);
1929 if (this.forceFit) {
1930 scroller.setStyle('overflow-x', 'hidden');
1934 * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
1935 * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
1937 * @property mainBody
1945 innerHd : mainHd.child('div.x-grid3-header-inner').dom,
1946 mainBody: new Element(Element.fly(scroller).child('div.x-grid3-body')),
1947 focusEl : new Element(Element.fly(scroller).child('a')),
1949 resizeMarker: new Element(el.child('div.x-grid3-resize-marker')),
1950 resizeProxy : new Element(el.child('div.x-grid3-resize-proxy'))
1953 this.focusEl.swallowEvent('click', true);
1957 getRows : function() {
1958 return this.hasRows() ? this.mainBody.dom.childNodes : [];
1961 // finder methods, used with delegation
1964 findCell : function(el) {
1968 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
1972 * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
1973 * See also {@link #findRowIndex}
1974 * @param {HTMLElement} el The target element
1975 * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
1977 findCellIndex : function(el, requiredCls) {
1978 var cell = this.findCell(el),
1982 hasCls = this.fly(cell).hasClass(requiredCls);
1983 if (!requiredCls || hasCls) {
1984 return this.getCellIndex(cell);
1991 getCellIndex : function(el) {
1993 var match = el.className.match(this.colRe);
1995 if (match && match[1]) {
1996 return this.cm.getIndexById(match[1]);
2003 findHeaderCell : function(el) {
2004 var cell = this.findCell(el);
2005 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
2009 findHeaderIndex : function(el){
2010 return this.findCellIndex(el, this.hdCls);
2014 * Return the HtmlElement representing the grid row which contains the passed element.
2015 * @param {HTMLElement} el The target HTMLElement
2016 * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
2018 findRow : function(el) {
2022 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
2026 * Return the index of the grid row which contains the passed HTMLElement.
2027 * See also {@link #findCellIndex}
2028 * @param {HTMLElement} el The target HTMLElement
2029 * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
2031 findRowIndex : function(el) {
2032 var row = this.findRow(el);
2033 return row ? row.rowIndex : false;
2037 * Return the HtmlElement representing the grid row body which contains the passed element.
2038 * @param {HTMLElement} el The target HTMLElement
2039 * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
2041 findRowBody : function(el) {
2046 return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
2049 // getter methods for fetching elements dynamically in the grid
2052 * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
2053 * @param {Number} index The row index
2054 * @return {HtmlElement} The div element.
2056 getRow : function(row) {
2057 return this.getRows()[row];
2061 * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
2062 * @param {Number} row The row index in which to find the cell.
2063 * @param {Number} col The column index of the cell.
2064 * @return {HtmlElement} The td at the specified coordinates.
2066 getCell : function(row, col) {
2067 return Ext.fly(this.getRow(row)).query(this.cellSelector)[col];
2071 * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
2072 * @param {Number} index The column index
2073 * @return {HtmlElement} The td element.
2075 getHeaderCell : function(index) {
2076 return this.mainHd.dom.getElementsByTagName('td')[index];
2079 // manipulating elements
2081 // private - use getRowClass to apply custom row classes
2082 addRowClass : function(rowId, cls) {
2083 var row = this.getRow(rowId);
2085 this.fly(row).addClass(cls);
2090 removeRowClass : function(row, cls) {
2091 var r = this.getRow(row);
2093 this.fly(r).removeClass(cls);
2098 removeRow : function(row) {
2099 Ext.removeNode(this.getRow(row));
2100 this.syncFocusEl(row);
2104 removeRows : function(firstRow, lastRow) {
2105 var bd = this.mainBody.dom,
2108 for (rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
2109 Ext.removeNode(bd.childNodes[firstRow]);
2112 this.syncFocusEl(firstRow);
2115 /* ----------------------------------- Scrolling functions -------------------------------------------*/
2118 getScrollState : function() {
2119 var sb = this.scroller.dom;
2122 left: sb.scrollLeft,
2128 restoreScroll : function(state) {
2129 var sb = this.scroller.dom;
2130 sb.scrollLeft = state.left;
2131 sb.scrollTop = state.top;
2135 * Scrolls the grid to the top
2137 scrollToTop : function() {
2138 var dom = this.scroller.dom;
2145 syncScroll : function() {
2146 this.syncHeaderScroll();
2147 var mb = this.scroller.dom;
2148 this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
2152 syncHeaderScroll : function() {
2153 var innerHd = this.innerHd,
2154 scrollLeft = this.scroller.dom.scrollLeft;
2156 innerHd.scrollLeft = scrollLeft;
2157 innerHd.scrollLeft = scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
2162 * Ensures the given column has the given icon class
2164 updateSortIcon : function(col, dir) {
2165 var sortClasses = this.sortClasses,
2166 sortClass = sortClasses[dir == "DESC" ? 1 : 0],
2167 headers = this.mainHd.select('td').removeClass(sortClasses);
2169 headers.item(col).addClass(sortClass);
2174 * Updates the size of every column and cell in the grid
2176 updateAllColumnWidths : function() {
2177 var totalWidth = this.getTotalWidth(),
2178 colCount = this.cm.getColumnCount(),
2179 rows = this.getRows(),
2180 rowCount = rows.length,
2182 row, rowFirstChild, trow, i, j;
2184 for (i = 0; i < colCount; i++) {
2185 widths[i] = this.getColumnWidth(i);
2186 this.getHeaderCell(i).style.width = widths[i];
2189 this.updateHeaderWidth();
2191 for (i = 0; i < rowCount; i++) {
2193 row.style.width = totalWidth;
2194 rowFirstChild = row.firstChild;
2196 if (rowFirstChild) {
2197 rowFirstChild.style.width = totalWidth;
2198 trow = rowFirstChild.rows[0];
2200 for (j = 0; j < colCount; j++) {
2201 trow.childNodes[j].style.width = widths[j];
2206 this.onAllColumnWidthsUpdated(widths, totalWidth);
2211 * Called after a column's width has been updated, this resizes all of the cells for that column in each row
2212 * @param {Number} column The column index
2214 updateColumnWidth : function(column, width) {
2215 var columnWidth = this.getColumnWidth(column),
2216 totalWidth = this.getTotalWidth(),
2217 headerCell = this.getHeaderCell(column),
2218 nodes = this.getRows(),
2219 nodeCount = nodes.length,
2222 this.updateHeaderWidth();
2223 headerCell.style.width = columnWidth;
2225 for (i = 0; i < nodeCount; i++) {
2227 firstChild = row.firstChild;
2229 row.style.width = totalWidth;
2231 firstChild.style.width = totalWidth;
2232 firstChild.rows[0].childNodes[column].style.width = columnWidth;
2236 this.onColumnWidthUpdated(column, columnWidth, totalWidth);
2241 * Sets the hidden status of a given column.
2242 * @param {Number} col The column index
2243 * @param {Boolean} hidden True to make the column hidden
2245 updateColumnHidden : function(col, hidden) {
2246 var totalWidth = this.getTotalWidth(),
2247 display = hidden ? 'none' : '',
2248 headerCell = this.getHeaderCell(col),
2249 nodes = this.getRows(),
2250 nodeCount = nodes.length,
2251 row, rowFirstChild, i;
2253 this.updateHeaderWidth();
2254 headerCell.style.display = display;
2256 for (i = 0; i < nodeCount; i++) {
2258 row.style.width = totalWidth;
2259 rowFirstChild = row.firstChild;
2261 if (rowFirstChild) {
2262 rowFirstChild.style.width = totalWidth;
2263 rowFirstChild.rows[0].childNodes[col].style.display = display;
2267 this.onColumnHiddenUpdated(col, hidden, totalWidth);
2268 delete this.lastViewWidth; //recalc
2274 * Renders all of the rows to a string buffer and returns the string. This is called internally
2275 * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM.
2276 * @param {Array} columns The column data acquired from getColumnData.
2277 * @param {Array} records The array of records to render
2278 * @param {Ext.data.Store} store The store to render the rows from
2279 * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of
2280 * the rows so this is used to maintain logic for striping etc
2281 * @param {Number} colCount The total number of columns in the column model
2282 * @param {Boolean} stripe True to stripe the rows
2283 * @return {String} A string containing the HTML for the rendered rows
2285 doRender : function(columns, records, store, startRow, colCount, stripe) {
2286 var templates = this.templates,
2287 cellTemplate = templates.cell,
2288 rowTemplate = templates.row,
2289 last = colCount - 1,
2290 tstyle = 'width:' + this.getTotalWidth() + ';',
2294 rowParams = {tstyle: tstyle},
2296 len = records.length,
2299 record, i, j, rowIndex;
2301 //build up each row's HTML
2302 for (j = 0; j < len; j++) {
2303 record = records[j];
2306 rowIndex = j + startRow;
2308 //build up each column's HTML
2309 for (i = 0; i < colCount; i++) {
2310 column = columns[i];
2312 meta.id = column.id;
2313 meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
2314 meta.attr = meta.cellAttr = '';
2315 meta.style = column.style;
2316 meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
2318 if (Ext.isEmpty(meta.value)) {
2319 meta.value = ' ';
2322 if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
2323 meta.css += ' x-grid3-dirty-cell';
2326 colBuffer[colBuffer.length] = cellTemplate.apply(meta);
2330 //set up row striping and row dirtiness CSS classes
2331 if (stripe && ((rowIndex + 1) % 2 === 0)) {
2332 alt[0] = 'x-grid3-row-alt';
2336 alt[1] = ' x-grid3-dirty-row';
2339 rowParams.cols = colCount;
2341 if (this.getRowClass) {
2342 alt[2] = this.getRowClass(record, rowIndex, rowParams, store);
2345 rowParams.alt = alt.join(' ');
2346 rowParams.cells = colBuffer.join('');
2348 rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams);
2351 return rowBuffer.join('');
2356 * Adds CSS classes and rowIndex to each row
2357 * @param {Number} startRow The row to start from (defaults to 0)
2359 processRows : function(startRow, skipStripe) {
2360 if (!this.ds || this.ds.getCount() < 1) {
2364 var rows = this.getRows(),
2365 length = rows.length,
2368 skipStripe = skipStripe || !this.grid.stripeRows;
2369 startRow = startRow || 0;
2371 for (i = 0; i < length; i++) {
2376 row.className = row.className.replace(this.rowClsRe, ' ');
2377 if ((i + 1) % 2 === 0){
2378 row.className += ' x-grid3-row-alt';
2384 // add first/last-row classes
2385 if (startRow === 0) {
2386 Ext.fly(rows[0]).addClass(this.firstRowCls);
2389 Ext.fly(rows[length - 1]).addClass(this.lastRowCls);
2395 afterRender : function() {
2396 if (!this.ds || !this.cm) {
2400 this.mainBody.dom.innerHTML = this.renderBody() || ' ';
2401 this.processRows(0, true);
2403 if (this.deferEmptyText !== true) {
2404 this.applyEmptyText();
2407 this.grid.fireEvent('viewready', this.grid);
2412 * This is always intended to be called after renderUI. Sets up listeners on the UI elements
2413 * and sets up options like column menus, moving and resizing.
2415 afterRenderUI: function() {
2416 var grid = this.grid;
2418 this.initElements();
2420 // get mousedowns early
2421 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
2425 mouseover: this.handleHdOver,
2426 mouseout : this.handleHdOut,
2427 mousemove: this.handleHdMove
2430 this.scroller.on('scroll', this.syncScroll, this);
2432 if (grid.enableColumnResize !== false) {
2433 this.splitZone = new Ext.grid.GridView.SplitDragZone(grid, this.mainHd.dom);
2436 if (grid.enableColumnMove) {
2437 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(grid, this.innerHd);
2438 this.columnDrop = new Ext.grid.HeaderDropZone(grid, this.mainHd.dom);
2441 if (grid.enableHdMenu !== false) {
2442 this.hmenu = new Ext.menu.Menu({id: grid.id + '-hctx'});
2444 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
2445 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
2448 if (grid.enableColumnHide !== false) {
2449 this.colMenu = new Ext.menu.Menu({id:grid.id + '-hcols-menu'});
2452 beforeshow: this.beforeColMenuShow,
2453 itemclick : this.handleHdMenuClick
2455 this.hmenu.add('-', {
2458 text: this.columnsText,
2460 iconCls: 'x-cols-icon'
2464 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
2467 if (grid.trackMouseOver) {
2470 mouseover: this.onRowOver,
2471 mouseout : this.onRowOut
2475 if (grid.enableDragDrop || grid.enableDrag) {
2476 this.dragZone = new Ext.grid.GridDragZone(grid, {
2477 ddGroup : grid.ddGroup || 'GridDD'
2481 this.updateHeaderSortState();
2486 * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not
2487 * render rows from the store, just the surrounding UI elements.
2489 renderUI : function() {
2490 var templates = this.templates;
2492 return templates.master.apply({
2493 body : templates.body.apply({rows:' '}),
2494 header: this.renderHeaders(),
2495 ostyle: 'width:' + this.getOffsetWidth() + ';',
2496 bstyle: 'width:' + this.getTotalWidth() + ';'
2501 processEvent : function(name, e) {
2502 var target = e.getTarget(),
2504 header = this.findHeaderIndex(target),
2505 row, cell, col, body;
2507 grid.fireEvent(name, e);
2509 if (header !== false) {
2510 grid.fireEvent('header' + name, grid, header, e);
2512 row = this.findRowIndex(target);
2514 // Grid's value-added events must bubble correctly to allow cancelling via returning false: cell->column->row
2515 // We must allow a return of false at any of these levels to cancel the event processing.
2516 // Particularly allowing rowmousedown to be cancellable by prior handlers which need to prevent selection.
2517 if (row !== false) {
2518 cell = this.findCellIndex(target);
2519 if (cell !== false) {
2520 col = grid.colModel.getColumnAt(cell);
2521 if (grid.fireEvent('cell' + name, grid, row, cell, e) !== false) {
2522 if (!col || (col.processEvent && (col.processEvent(name, e, grid, row, cell) !== false))) {
2523 grid.fireEvent('row' + name, grid, row, e);
2527 if (grid.fireEvent('row' + name, grid, row, e) !== false) {
2528 (body = this.findRowBody(target)) && grid.fireEvent('rowbody' + name, grid, row, e);
2532 grid.fireEvent('container' + name, grid, e);
2539 * Sizes the grid's header and body elements
2541 layout : function(initial) {
2542 if (!this.mainBody) {
2543 return; // not rendered
2546 var grid = this.grid,
2547 gridEl = grid.getGridEl(),
2548 gridSize = gridEl.getSize(true),
2549 gridWidth = gridSize.width,
2550 gridHeight = gridSize.height,
2551 scroller = this.scroller,
2552 scrollStyle, headerHeight, scrollHeight;
2554 if (gridWidth < 20 || gridHeight < 20) {
2558 if (grid.autoHeight) {
2559 scrollStyle = scroller.dom.style;
2560 scrollStyle.overflow = 'visible';
2563 scrollStyle.position = 'static';
2566 this.el.setSize(gridWidth, gridHeight);
2568 headerHeight = this.mainHd.getHeight();
2569 scrollHeight = gridHeight - headerHeight;
2571 scroller.setSize(gridWidth, scrollHeight);
2574 this.innerHd.style.width = (gridWidth) + "px";
2578 if (this.forceFit || (initial === true && this.autoFill)) {
2579 if (this.lastViewWidth != gridWidth) {
2580 this.fitColumns(false, false);
2581 this.lastViewWidth = gridWidth;
2585 this.syncHeaderScroll();
2588 this.onLayout(gridWidth, scrollHeight);
2591 // template functions for subclasses and plugins
2592 // these functions include precalculated values
2593 onLayout : function(vw, vh) {
2597 onColumnWidthUpdated : function(col, w, tw) {
2601 onAllColumnWidthsUpdated : function(ws, tw) {
2605 onColumnHiddenUpdated : function(col, hidden, tw) {
2609 updateColumnText : function(col, text) {
2613 afterMove : function(colIndex) {
2617 /* ----------------------------------- Core Specific -------------------------------------------*/
2619 init : function(grid) {
2622 this.initTemplates();
2623 this.initData(grid.store, grid.colModel);
2628 getColumnId : function(index){
2629 return this.cm.getColumnId(index);
2633 getOffsetWidth : function() {
2634 return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
2638 getScrollOffset: function() {
2639 return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
2644 * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just
2646 * @return {String} Rendered header row
2648 renderHeaders : function() {
2649 var colModel = this.cm,
2650 templates = this.templates,
2651 headerTpl = templates.hcell,
2653 colCount = colModel.getColumnCount(),
2654 last = colCount - 1,
2658 for (i = 0; i < colCount; i++) {
2660 cssCls = 'x-grid3-cell-first ';
2662 cssCls = i == last ? 'x-grid3-cell-last ' : '';
2666 id : colModel.getColumnId(i),
2667 value : colModel.getColumnHeader(i) || '',
2668 style : this.getColumnStyle(i, true),
2670 tooltip: this.getColumnTooltip(i)
2673 if (colModel.config[i].align == 'right') {
2674 properties.istyle = 'padding-right: 16px;';
2676 delete properties.istyle;
2679 cells[i] = headerTpl.apply(properties);
2682 return templates.header.apply({
2683 cells : cells.join(""),
2684 tstyle: String.format("width: {0};", this.getTotalWidth())
2691 getColumnTooltip : function(i) {
2692 var tooltip = this.cm.getColumnTooltip(i);
2694 if (Ext.QuickTips.isEnabled()) {
2695 return 'ext:qtip="' + tooltip + '"';
2697 return 'title="' + tooltip + '"';
2705 beforeUpdate : function() {
2706 this.grid.stopEditing(true);
2711 * Re-renders the headers and ensures they are sized correctly
2713 updateHeaders : function() {
2714 this.innerHd.firstChild.innerHTML = this.renderHeaders();
2716 this.updateHeaderWidth(false);
2721 * Ensures that the header is sized to the total width available to it
2722 * @param {Boolean} updateMain True to update the mainBody's width also (defaults to true)
2724 updateHeaderWidth: function(updateMain) {
2725 var innerHdChild = this.innerHd.firstChild,
2726 totalWidth = this.getTotalWidth();
2728 innerHdChild.style.width = this.getOffsetWidth();
2729 innerHdChild.firstChild.style.width = totalWidth;
2731 if (updateMain !== false) {
2732 this.mainBody.dom.style.width = totalWidth;
2737 * Focuses the specified row.
2738 * @param {Number} row The row index
2740 focusRow : function(row) {
2741 this.focusCell(row, 0, false);
2745 * Focuses the specified cell.
2746 * @param {Number} row The row index
2747 * @param {Number} col The column index
2749 focusCell : function(row, col, hscroll) {
2750 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
2752 var focusEl = this.focusEl;
2757 focusEl.focus.defer(1, focusEl);
2763 * Finds the Elements corresponding to the given row and column indexes
2765 resolveCell : function(row, col, hscroll) {
2766 if (!Ext.isNumber(row)) {
2774 if (row < 0 || row >= this.ds.getCount()) {
2777 col = (col !== undefined ? col : 0);
2779 var rowEl = this.getRow(row),
2781 colCount = colModel.getColumnCount(),
2784 if (!(hscroll === false && col === 0)) {
2785 while (col < colCount && colModel.isHidden(col)) {
2789 cellEl = this.getCell(row, col);
2792 return {row: rowEl, cell: cellEl};
2797 * Returns the XY co-ordinates of a given row/cell resolution (see {@link #resolveCell})
2798 * @return {Array} X and Y coords
2800 getResolvedXY : function(resolved) {
2805 var cell = resolved.cell,
2809 return Ext.fly(cell).getXY();
2811 return [this.el.getX(), Ext.fly(row).getY()];
2817 * Moves the focus element to the x and y co-ordinates of the given row and column
2819 syncFocusEl : function(row, col, hscroll) {
2822 if (!Ext.isArray(xy)) {
2823 row = Math.min(row, Math.max(0, this.getRows().length-1));
2829 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
2832 this.focusEl.setXY(xy || this.scroller.getXY());
2838 ensureVisible : function(row, col, hscroll) {
2839 var resolved = this.resolveCell(row, col, hscroll);
2841 if (!resolved || !resolved.row) {
2845 var rowEl = resolved.row,
2846 cellEl = resolved.cell,
2847 c = this.scroller.dom,
2852 while (p && p != stop) {
2853 ctop += p.offsetTop;
2857 ctop -= this.mainHd.dom.offsetHeight;
2858 stop = parseInt(c.scrollTop, 10);
2860 var cbot = ctop + rowEl.offsetHeight,
2861 ch = c.clientHeight,
2867 } else if(cbot > sbot) {
2868 c.scrollTop = cbot-ch;
2871 if (hscroll !== false) {
2872 var cleft = parseInt(cellEl.offsetLeft, 10),
2873 cright = cleft + cellEl.offsetWidth,
2874 sleft = parseInt(c.scrollLeft, 10),
2875 sright = sleft + c.clientWidth;
2877 if (cleft < sleft) {
2878 c.scrollLeft = cleft;
2879 } else if(cright > sright) {
2880 c.scrollLeft = cright-c.clientWidth;
2884 return this.getResolvedXY(resolved);
2888 insertRows : function(dm, firstRow, lastRow, isUpdate) {
2889 var last = dm.getCount() - 1;
2890 if( !isUpdate && firstRow === 0 && lastRow >= last) {
2891 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
2893 this.fireEvent('rowsinserted', this, firstRow, lastRow);
2896 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
2898 var html = this.renderRows(firstRow, lastRow),
2899 before = this.getRow(firstRow);
2902 Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
2904 Ext.DomHelper.insertHtml('beforeBegin', before, html);
2906 var r = this.getRow(last - 1);
2908 Ext.fly(r).removeClass(this.lastRowCls);
2910 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
2913 this.fireEvent('rowsinserted', this, firstRow, lastRow);
2914 this.processRows(firstRow);
2915 } else if (firstRow === 0 || firstRow >= last) {
2916 //ensure first/last row is kept after an update.
2917 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
2920 this.syncFocusEl(firstRow);
2925 * DEPRECATED - this doesn't appear to be called anywhere in the library, remove in 4.0.
2927 deleteRows : function(dm, firstRow, lastRow) {
2928 if (dm.getRowCount() < 1) {
2931 this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
2933 this.removeRows(firstRow, lastRow);
2935 this.processRows(firstRow);
2936 this.fireEvent('rowsdeleted', this, firstRow, lastRow);
2942 * Builds a CSS string for the given column index
2943 * @param {Number} colIndex The column index
2944 * @param {Boolean} isHeader True if getting the style for the column's header
2945 * @return {String} The CSS string
2947 getColumnStyle : function(colIndex, isHeader) {
2948 var colModel = this.cm,
2949 colConfig = colModel.config,
2950 style = isHeader ? '' : colConfig[colIndex].css || '',
2951 align = colConfig[colIndex].align;
2953 style += String.format("width: {0};", this.getColumnWidth(colIndex));
2955 if (colModel.isHidden(colIndex)) {
2956 style += 'display: none; ';
2960 style += String.format("text-align: {0};", align);
2968 * Returns the width of a given column minus its border width
2969 * @return {Number} The column index
2970 * @return {String|Number} The width in pixels
2972 getColumnWidth : function(column) {
2973 var columnWidth = this.cm.getColumnWidth(column),
2974 borderWidth = this.borderWidth;
2976 if (Ext.isNumber(columnWidth)) {
2977 if (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2)) {
2978 return columnWidth + "px";
2980 return Math.max(columnWidth - borderWidth, 0) + "px";
2989 * Returns the total width of all visible columns
2992 getTotalWidth : function() {
2993 return this.cm.getTotalWidth() + 'px';
2998 * Resizes each column to fit the available grid width.
2999 * TODO: The second argument isn't even used, remove it in 4.0
3000 * @param {Boolean} preventRefresh True to prevent resizing of each row to the new column sizes (defaults to false)
3001 * @param {null} onlyExpand NOT USED, will be removed in 4.0
3002 * @param {Number} omitColumn The index of a column to leave at its current width. Defaults to undefined
3003 * @return {Boolean} True if the operation succeeded, false if not or undefined if the grid view is not yet initialized
3005 fitColumns : function(preventRefresh, onlyExpand, omitColumn) {
3006 var grid = this.grid,
3008 totalColWidth = colModel.getTotalWidth(false),
3009 gridWidth = this.getGridInnerWidth(),
3010 extraWidth = gridWidth - totalColWidth,
3014 colWidth, fraction, i;
3016 // not initialized, so don't screw up the default widths
3017 if (gridWidth < 20 || extraWidth === 0) {
3021 var visibleColCount = colModel.getColumnCount(true),
3022 totalColCount = colModel.getColumnCount(false),
3023 adjCount = visibleColCount - (Ext.isNumber(omitColumn) ? 1 : 0);
3025 if (adjCount === 0) {
3027 omitColumn = undefined;
3030 //FIXME: the algorithm used here is odd and potentially confusing. Includes this for loop and the while after it.
3031 for (i = 0; i < totalColCount; i++) {
3032 if (!colModel.isFixed(i) && i !== omitColumn) {
3033 colWidth = colModel.getColumnWidth(i);
3034 columns.push(i, colWidth);
3036 if (!colModel.isHidden(i)) {
3043 fraction = (gridWidth - colModel.getTotalWidth()) / width;
3045 while (columns.length) {
3046 colWidth = columns.pop();
3049 colModel.setColumnWidth(i, Math.max(grid.minColumnWidth, Math.floor(colWidth + colWidth * fraction)), true);
3052 //this has been changed above so remeasure now
3053 totalColWidth = colModel.getTotalWidth(false);
3055 if (totalColWidth > gridWidth) {
3056 var adjustCol = (adjCount == visibleColCount) ? extraCol : omitColumn,
3057 newWidth = Math.max(1, colModel.getColumnWidth(adjustCol) - (totalColWidth - gridWidth));
3059 colModel.setColumnWidth(adjustCol, newWidth, true);
3062 if (preventRefresh !== true) {
3063 this.updateAllColumnWidths();
3071 * Resizes the configured autoExpandColumn to take the available width after the other columns have
3072 * been accounted for
3073 * @param {Boolean} preventUpdate True to prevent the resizing of all rows (defaults to false)
3075 autoExpand : function(preventUpdate) {
3076 var grid = this.grid,
3078 gridWidth = this.getGridInnerWidth(),
3079 totalColumnWidth = colModel.getTotalWidth(false),
3080 autoExpandColumn = grid.autoExpandColumn;
3082 if (!this.userResized && autoExpandColumn) {
3083 if (gridWidth != totalColumnWidth) {
3084 //if we are not already using all available width, resize the autoExpandColumn
3085 var colIndex = colModel.getIndexById(autoExpandColumn),
3086 currentWidth = colModel.getColumnWidth(colIndex),
3087 desiredWidth = gridWidth - totalColumnWidth + currentWidth,
3088 newWidth = Math.min(Math.max(desiredWidth, grid.autoExpandMin), grid.autoExpandMax);
3090 if (currentWidth != newWidth) {
3091 colModel.setColumnWidth(colIndex, newWidth, true);
3093 if (preventUpdate !== true) {
3094 this.updateColumnWidth(colIndex, newWidth);
3102 * Returns the total internal width available to the grid, taking the scrollbar into account
3103 * @return {Number} The total width
3105 getGridInnerWidth: function() {
3106 return this.grid.getGridEl().getWidth(true) - this.getScrollOffset();
3111 * Returns an array of column configurations - one for each column
3112 * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
3114 getColumnData : function() {
3117 colCount = colModel.getColumnCount(),
3118 fields = this.ds.fields,
3121 for (i = 0; i < colCount; i++) {
3122 name = colModel.getDataIndex(i);
3125 name : Ext.isDefined(name) ? name : (fields.get(i) ? fields.get(i).name : undefined),
3126 renderer: colModel.getRenderer(i),
3127 scope : colModel.getRendererScope(i),
3128 id : colModel.getColumnId(i),
3129 style : this.getColumnStyle(i)
3138 * Renders rows between start and end indexes
3139 * @param {Number} startRow Index of the first row to render
3140 * @param {Number} endRow Index of the last row to render
3142 renderRows : function(startRow, endRow) {
3143 var grid = this.grid,
3145 stripe = grid.stripeRows,
3146 colModel = grid.colModel,
3147 colCount = colModel.getColumnCount(),
3148 rowCount = store.getCount(),
3155 startRow = startRow || 0;
3156 endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
3157 records = store.getRange(startRow, endRow);
3159 return this.doRender(this.getColumnData(), records, store, startRow, colCount, stripe);
3163 renderBody : function(){
3164 var markup = this.renderRows() || ' ';
3165 return this.templates.body.apply({rows: markup});
3170 * Refreshes a row by re-rendering it. Fires the rowupdated event when done
3172 refreshRow: function(record) {
3173 var store = this.ds,
3174 colCount = this.cm.getColumnCount(),
3175 columns = this.getColumnData(),
3176 last = colCount - 1,
3177 cls = ['x-grid3-row'],
3179 tstyle: String.format("width: {0};", this.getTotalWidth())
3182 cellTpl = this.templates.cell,
3183 rowIndex, row, column, meta, css, i;
3185 if (Ext.isNumber(record)) {
3187 record = store.getAt(rowIndex);
3189 rowIndex = store.indexOf(record);
3192 //the record could not be found
3193 if (!record || rowIndex < 0) {
3197 //builds each column in this row
3198 for (i = 0; i < colCount; i++) {
3199 column = columns[i];
3202 css = 'x-grid3-cell-first';
3204 css = (i == last) ? 'x-grid3-cell-last ' : '';
3209 style : column.style,
3214 // Need to set this after, because we pass meta to the renderer
3215 meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
3217 if (Ext.isEmpty(meta.value)) {
3218 meta.value = ' ';
3221 if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
3222 meta.css += ' x-grid3-dirty-cell';
3225 colBuffer[i] = cellTpl.apply(meta);
3228 row = this.getRow(rowIndex);
3231 if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
3232 cls.push('x-grid3-row-alt');
3235 if (this.getRowClass) {
3236 rowParams.cols = colCount;
3237 cls.push(this.getRowClass(record, rowIndex, rowParams, store));
3240 this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
3241 rowParams.cells = colBuffer.join("");
3242 row.innerHTML = this.templates.rowInner.apply(rowParams);
3244 this.fireEvent('rowupdated', this, rowIndex, record);
3248 * Refreshs the grid UI
3249 * @param {Boolean} headersToo (optional) True to also refresh the headers
3251 refresh : function(headersToo) {
3252 this.fireEvent('beforerefresh', this);
3253 this.grid.stopEditing(true);
3255 var result = this.renderBody();
3256 this.mainBody.update(result).setWidth(this.getTotalWidth());
3257 if (headersToo === true) {
3258 this.updateHeaders();
3259 this.updateHeaderSortState();
3261 this.processRows(0, true);
3263 this.applyEmptyText();
3264 this.fireEvent('refresh', this);
3269 * Displays the configured emptyText if there are currently no rows to display
3271 applyEmptyText : function() {
3272 if (this.emptyText && !this.hasRows()) {
3273 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
3279 * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
3280 * if the sorting has changed since this function was last run.
3282 updateHeaderSortState : function() {
3283 var state = this.ds.getSortState();
3288 if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
3289 this.grid.fireEvent('sortchange', this.grid, state);
3292 this.sortState = state;
3294 var sortColumn = this.cm.findColumnIndex(state.field);
3295 if (sortColumn != -1) {
3296 var sortDir = state.direction;
3297 this.updateSortIcon(sortColumn, sortDir);
3303 * Removes any sorting indicator classes from the column headers
3305 clearHeaderSortState : function() {
3306 if (!this.sortState) {
3309 this.grid.fireEvent('sortchange', this.grid, null);
3310 this.mainHd.select('td').removeClass(this.sortClasses);
3311 delete this.sortState;
3316 * Destroys all objects associated with the GridView
3318 destroy : function() {
3321 gridEl = grid.getGridEl(),
3322 dragZone = me.dragZone,
3323 splitZone = me.splitZone,
3324 columnDrag = me.columnDrag,
3325 columnDrop = me.columnDrop,
3326 scrollToTopTask = me.scrollToTopTask,
3330 if (scrollToTopTask && scrollToTopTask.cancel) {
3331 scrollToTopTask.cancel();
3334 Ext.destroyMembers(me, 'colMenu', 'hmenu');
3336 me.initData(null, null);
3337 me.purgeListeners();
3339 Ext.fly(me.innerHd).un("click", me.handleHdDown, me);
3341 if (grid.enableColumnMove) {
3342 columnDragData = columnDrag.dragData;
3343 columnDragProxy = columnDrag.proxy;
3346 columnDragProxy.ghost,
3349 columnDrop.proxyTop,
3350 columnDrop.proxyBottom,
3351 columnDragData.ddel,
3352 columnDragData.header
3355 if (columnDragProxy.anim) {
3356 Ext.destroy(columnDragProxy.anim);
3359 delete columnDragProxy.ghost;
3360 delete columnDragData.ddel;
3361 delete columnDragData.header;
3362 columnDrag.destroy();
3364 delete Ext.dd.DDM.locationCache[columnDrag.id];
3365 delete columnDrag._domRef;
3367 delete columnDrop.proxyTop;
3368 delete columnDrop.proxyBottom;
3369 columnDrop.destroy();
3370 delete Ext.dd.DDM.locationCache["gridHeader" + gridEl.id];
3371 delete columnDrop._domRef;
3372 delete Ext.dd.DDM.ids[columnDrop.ddGroup];
3375 if (splitZone) { // enableColumnResize
3376 splitZone.destroy();
3377 delete splitZone._domRef;
3378 delete Ext.dd.DDM.ids["gridSplitters" + gridEl.id];
3381 Ext.fly(me.innerHd).removeAllListeners();
3382 Ext.removeNode(me.innerHd);
3400 delete grid.container;
3406 Ext.dd.DDM.currentTarget = null;
3407 delete Ext.dd.DDM.locationCache[gridEl.id];
3409 Ext.EventManager.removeResizeListener(me.onWindowResize, me);
3413 onDenyColumnHide : function() {
3418 render : function() {
3419 if (this.autoFill) {
3420 var ct = this.grid.ownerCt;
3422 if (ct && ct.getLayout()) {
3423 ct.on('afterlayout', function() {
3424 this.fitColumns(true, true);
3425 this.updateHeaders();
3426 this.updateHeaderSortState();
3427 }, this, {single: true});
3429 } else if (this.forceFit) {
3430 this.fitColumns(true, false);
3431 } else if (this.grid.autoExpandColumn) {
3432 this.autoExpand(true);
3435 this.grid.getGridEl().dom.innerHTML = this.renderUI();
3437 this.afterRenderUI();
3440 /* --------------------------------- Model Events and Handlers --------------------------------*/
3444 * Binds a new Store and ColumnModel to this GridView. Removes any listeners from the old objects (if present)
3445 * and adds listeners to the new ones
3446 * @param {Ext.data.Store} newStore The new Store instance
3447 * @param {Ext.grid.ColumnModel} newColModel The new ColumnModel instance
3449 initData : function(newStore, newColModel) {
3453 var oldStore = me.ds;
3455 oldStore.un('add', me.onAdd, me);
3456 oldStore.un('load', me.onLoad, me);
3457 oldStore.un('clear', me.onClear, me);
3458 oldStore.un('remove', me.onRemove, me);
3459 oldStore.un('update', me.onUpdate, me);
3460 oldStore.un('datachanged', me.onDataChange, me);
3462 if (oldStore !== newStore && oldStore.autoDestroy) {
3472 remove : me.onRemove,
3473 update : me.onUpdate,
3475 datachanged: me.onDataChange
3480 var oldColModel = me.cm;
3482 oldColModel.un('configchange', me.onColConfigChange, me);
3483 oldColModel.un('widthchange', me.onColWidthChange, me);
3484 oldColModel.un('headerchange', me.onHeaderChange, me);
3485 oldColModel.un('hiddenchange', me.onHiddenChange, me);
3486 oldColModel.un('columnmoved', me.onColumnMove, me);
3490 delete me.lastViewWidth;
3494 configchange: me.onColConfigChange,
3495 widthchange : me.onColWidthChange,
3496 headerchange: me.onHeaderChange,
3497 hiddenchange: me.onHiddenChange,
3498 columnmoved : me.onColumnMove
3503 me.cm = newColModel;
3507 onDataChange : function(){
3509 this.updateHeaderSortState();
3510 this.syncFocusEl(0);
3514 onClear : function() {
3516 this.syncFocusEl(0);
3520 onUpdate : function(store, record) {
3521 this.refreshRow(record);
3525 onAdd : function(store, records, index) {
3526 this.insertRows(store, index, index + (records.length-1));
3530 onRemove : function(store, record, index, isUpdate) {
3531 if (isUpdate !== true) {
3532 this.fireEvent('beforerowremoved', this, index, record);
3535 this.removeRow(index);
3537 if (isUpdate !== true) {
3538 this.processRows(index);
3539 this.applyEmptyText();
3540 this.fireEvent('rowremoved', this, index, record);
3546 * Called when a store is loaded, scrolls to the top row
3548 onLoad : function() {
3550 if (!this.scrollToTopTask) {
3551 this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
3553 this.scrollToTopTask.delay(1);
3560 onColWidthChange : function(cm, col, width) {
3561 this.updateColumnWidth(col, width);
3565 onHeaderChange : function(cm, col, text) {
3566 this.updateHeaders();
3570 onHiddenChange : function(cm, col, hidden) {
3571 this.updateColumnHidden(col, hidden);
3575 onColumnMove : function(cm, oldIndex, newIndex) {
3576 this.indexMap = null;
3578 this.restoreScroll(this.getScrollState());
3580 this.afterMove(newIndex);
3581 this.grid.fireEvent('columnmove', oldIndex, newIndex);
3585 onColConfigChange : function() {
3586 delete this.lastViewWidth;
3587 this.indexMap = null;
3591 /* -------------------- UI Events and Handlers ------------------------------ */
3593 initUI : function(grid) {
3594 grid.on('headerclick', this.onHeaderClick, this);
3598 initEvents : Ext.emptyFn,
3601 onHeaderClick : function(g, index) {
3602 if (this.headersDisabled || !this.cm.isSortable(index)) {
3605 g.stopEditing(true);
3606 g.store.sort(this.cm.getDataIndex(index));
3611 * Adds the hover class to a row when hovered over
3613 onRowOver : function(e, target) {
3614 var row = this.findRowIndex(target);
3616 if (row !== false) {
3617 this.addRowClass(row, this.rowOverCls);
3623 * Removes the hover class from a row on mouseout
3625 onRowOut : function(e, target) {
3626 var row = this.findRowIndex(target);
3628 if (row !== false && !e.within(this.getRow(row), true)) {
3629 this.removeRowClass(row, this.rowOverCls);
3634 onRowSelect : function(row) {
3635 this.addRowClass(row, this.selectedRowClass);
3639 onRowDeselect : function(row) {
3640 this.removeRowClass(row, this.selectedRowClass);
3644 onCellSelect : function(row, col) {
3645 var cell = this.getCell(row, col);
3647 this.fly(cell).addClass('x-grid3-cell-selected');
3652 onCellDeselect : function(row, col) {
3653 var cell = this.getCell(row, col);
3655 this.fly(cell).removeClass('x-grid3-cell-selected');
3660 handleWheel : function(e) {
3661 e.stopPropagation();
3666 * Called by the SplitDragZone when a drag has been completed. Resizes the columns
3668 onColumnSplitterMoved : function(cellIndex, width) {
3669 this.userResized = true;
3670 this.grid.colModel.setColumnWidth(cellIndex, width, true);
3672 if (this.forceFit) {
3673 this.fitColumns(true, false, cellIndex);
3674 this.updateAllColumnWidths();
3676 this.updateColumnWidth(cellIndex, width);
3677 this.syncHeaderScroll();
3680 this.grid.fireEvent('columnresize', cellIndex, width);
3685 * Click handler for the shared column dropdown menu, called on beforeshow. Builds the menu
3686 * which displays the list of columns for the user to show or hide.
3688 beforeColMenuShow : function() {
3689 var colModel = this.cm,
3690 colCount = colModel.getColumnCount(),
3691 colMenu = this.colMenu,
3694 colMenu.removeAll();
3696 for (i = 0; i < colCount; i++) {
3697 if (colModel.config[i].hideable !== false) {
3698 colMenu.add(new Ext.menu.CheckItem({
3699 text : colModel.getColumnHeader(i),
3700 itemId : 'col-' + colModel.getColumnId(i),
3701 checked : !colModel.isHidden(i),
3702 disabled : colModel.config[i].hideable === false,
3711 * Attached as the 'itemclick' handler to the header menu and the column show/hide submenu (if available).
3712 * Performs sorting if the sorter buttons were clicked, otherwise hides/shows the column that was clicked.
3714 handleHdMenuClick : function(item) {
3715 var store = this.ds,
3716 dataIndex = this.cm.getDataIndex(this.hdCtxIndex);
3718 switch (item.getItemId()) {
3720 store.sort(dataIndex, 'ASC');
3723 store.sort(dataIndex, 'DESC');
3726 this.handleHdMenuClickDefault(item);
3732 * Called by handleHdMenuClick if any button except a sort ASC/DESC button was clicked. The default implementation provides
3733 * the column hide/show functionality based on the check state of the menu item. A different implementation can be provided
3735 * @param {Ext.menu.BaseItem} item The menu item that was clicked
3737 handleHdMenuClickDefault: function(item) {
3738 var colModel = this.cm,
3739 itemId = item.getItemId(),
3740 index = colModel.getIndexById(itemId.substr(4));
3743 if (item.checked && colModel.getColumnsBy(this.isHideableColumn, this).length <= 1) {
3744 this.onDenyColumnHide();
3747 colModel.setHidden(index, item.checked);
3753 * Called when a header cell is clicked - shows the menu if the click happened over a trigger button
3755 handleHdDown : function(e, target) {
3756 if (Ext.fly(target).hasClass('x-grid3-hd-btn')) {
3759 var colModel = this.cm,
3760 header = this.findHeaderCell(target),
3761 index = this.getCellIndex(header),
3762 sortable = colModel.isSortable(index),
3764 menuItems = menu.items,
3765 menuCls = this.headerMenuOpenCls;
3767 this.hdCtxIndex = index;
3769 Ext.fly(header).addClass(menuCls);
3770 menuItems.get('asc').setDisabled(!sortable);
3771 menuItems.get('desc').setDisabled(!sortable);
3773 menu.on('hide', function() {
3774 Ext.fly(header).removeClass(menuCls);
3775 }, this, {single:true});
3777 menu.show(target, 'tl-bl?');
3783 * Attached to the headers' mousemove event. This figures out the CSS cursor to use based on where the mouse is currently
3784 * pointed. If the mouse is currently hovered over the extreme left or extreme right of any header cell and the cell next
3785 * to it is resizable it is given the resize cursor, otherwise the cursor is set to an empty string.
3787 handleHdMove : function(e) {
3788 var header = this.findHeaderCell(this.activeHdRef);
3790 if (header && !this.headersDisabled) {
3791 var handleWidth = this.splitHandleWidth || 5,
3792 activeRegion = this.activeHdRegion,
3793 headerStyle = header.style,
3796 pageX = e.getPageX();
3798 if (this.grid.enableColumnResize !== false) {
3799 var activeHeaderIndex = this.activeHdIndex,
3800 previousVisible = this.getPreviousVisible(activeHeaderIndex),
3801 currentResizable = colModel.isResizable(activeHeaderIndex),
3802 previousResizable = previousVisible && colModel.isResizable(previousVisible),
3803 inLeftResizer = pageX - activeRegion.left <= handleWidth,
3804 inRightResizer = activeRegion.right - pageX <= (!this.activeHdBtn ? handleWidth : 2);
3806 if (inLeftResizer && previousResizable) {
3807 cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
3808 } else if (inRightResizer && currentResizable) {
3809 cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
3813 headerStyle.cursor = cursor;
3819 * Returns the index of the nearest currently visible header to the left of the given index.
3820 * @param {Number} index The header index
3821 * @return {Number/undefined} The index of the nearest visible header
3823 getPreviousVisible: function(index) {
3825 if (!this.cm.isHidden(index - 1)) {
3835 * Tied to the header element's mouseover event - adds the over class to the header cell if the menu is not disabled
3838 handleHdOver : function(e, target) {
3839 var header = this.findHeaderCell(target);
3841 if (header && !this.headersDisabled) {
3842 var fly = this.fly(header);
3844 this.activeHdRef = target;
3845 this.activeHdIndex = this.getCellIndex(header);
3846 this.activeHdRegion = fly.getRegion();
3848 if (!this.isMenuDisabled(this.activeHdIndex, fly)) {
3849 fly.addClass('x-grid3-hd-over');
3850 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
3852 if (this.activeHdBtn) {
3853 this.activeHdBtn.dom.style.height = (header.firstChild.offsetHeight - 1) + 'px';
3861 * Tied to the header element's mouseout event. Removes the hover class from the header cell
3863 handleHdOut : function(e, target) {
3864 var header = this.findHeaderCell(target);
3866 if (header && (!Ext.isIE || !e.within(header, true))) {
3867 this.activeHdRef = null;
3868 this.fly(header).removeClass('x-grid3-hd-over');
3869 header.style.cursor = '';
3875 * Used by {@link #handleHdOver} to determine whether or not to show the header menu class on cell hover
3876 * @param {Number} cellIndex The header cell index
3877 * @param {Ext.Element} el The cell element currently being hovered over
3879 isMenuDisabled: function(cellIndex, el) {
3880 return this.cm.isMenuDisabled(cellIndex);
3885 * Returns true if there are any rows rendered into the GridView
3886 * @return {Boolean} True if any rows have been rendered
3888 hasRows : function() {
3889 var fc = this.mainBody.dom.firstChild;
3890 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
3896 isHideableColumn : function(c) {
3902 * DEPRECATED - will be removed in Ext JS 5.0
3904 bind : function(d, c) {
3905 this.initData(d, c);
3911 // This is a support class used internally by the Grid components
3912 Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
3914 constructor: function(grid, hd){
3916 this.view = grid.getView();
3917 this.marker = this.view.resizeMarker;
3918 this.proxy = this.view.resizeProxy;
3919 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
3920 'gridSplitters' + this.grid.getGridEl().id, {
3921 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
3923 this.scroll = false;
3924 this.hw = this.view.splitHandleWidth || 5;
3927 b4StartDrag : function(x, y){
3928 this.dragHeadersDisabled = this.view.headersDisabled;
3929 this.view.headersDisabled = true;
3930 var h = this.view.mainWrap.getHeight();
3931 this.marker.setHeight(h);
3933 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
3934 this.proxy.setHeight(h);
3935 var w = this.cm.getColumnWidth(this.cellIndex),
3936 minw = Math.max(w-this.grid.minColumnWidth, 0);
3937 this.resetConstraints();
3938 this.setXConstraint(minw, 1000);
3939 this.setYConstraint(0, 0);
3940 this.minX = x - minw;
3941 this.maxX = x + 1000;
3943 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
3946 allowHeaderDrag : function(e){
3950 handleMouseDown : function(e){
3951 var t = this.view.findHeaderCell(e.getTarget());
3952 if(t && this.allowHeaderDrag(e)){
3953 var xy = this.view.fly(t).getXY(),
3960 if((ex - x) <= this.hw){
3962 }else if((x+w) - ex <= this.hw){
3965 if(adjust !== false){
3966 this.cm = this.grid.colModel;
3967 var ci = this.view.getCellIndex(t);
3969 if (ci + adjust < 0) {
3972 while(this.cm.isHidden(ci+adjust)){
3979 this.cellIndex = ci+adjust;
3981 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
3982 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
3984 }else if(this.view.columnDrag){
3985 this.view.columnDrag.callHandleMouseDown(e);
3990 endDrag : function(e){
3993 endX = Math.max(this.minX, e.getPageX()),
3994 diff = endX - this.startPos,
3995 disabled = this.dragHeadersDisabled;
3997 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
3998 setTimeout(function(){
3999 v.headersDisabled = disabled;
4003 autoOffset : function(){
4008 * @class Ext.grid.PivotGridView
4009 * @extends Ext.grid.GridView
4010 * Specialised GridView for rendering Pivot Grid components. Config can be passed to the PivotGridView via the PivotGrid constructor's
4011 * viewConfig option:
4013 new Ext.grid.PivotGrid({
4015 title: 'My Pivot Grid',
4016 getCellCls: function(value) {
4017 return value > 10 'red' : 'green';
4022 * <p>Currently {@link #title} and {@link #getCellCls} are the only configuration options accepted by PivotGridView. All other
4023 * interaction is performed via the {@link Ext.grid.PivotGrid PivotGrid} class.</p>
4025 Ext.grid.PivotGridView = Ext.extend(Ext.grid.GridView, {
4028 * The CSS class added to all group header cells. Defaults to 'grid-hd-group-cell'
4029 * @property colHeaderCellCls
4032 colHeaderCellCls: 'grid-hd-group-cell',
4035 * @cfg {String} title Optional title to be placed in the top left corner of the PivotGrid. Defaults to an empty string.
4040 * @cfg {Function} getCellCls Optional function which should return a CSS class name for each cell value. This is useful when
4041 * color coding cells based on their value. Defaults to undefined.
4045 * Returns the headers to be rendered at the top of the grid. Should be a 2-dimensional array, where each item specifies the number
4046 * of columns it groups (column in this case refers to normal grid columns). In the example below we have 5 city groups, which are
4047 * each part of a continent supergroup. The colspan for each city group refers to the number of normal grid columns that group spans,
4048 * so in this case the grid would be expected to have a total of 12 columns:
4053 {header: 'England', colspan: 5},
4054 {header: 'USA', colspan: 3}
4059 {header: 'London', colspan: 2},
4060 {header: 'Cambridge', colspan: 3},
4061 {header: 'Palo Alto', colspan: 3}
4066 * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
4067 * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
4068 * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
4069 * be the sum of all child nodes beneath this node.
4071 getColumnHeaders: function() {
4072 return this.grid.topAxis.buildHeaders();;
4076 * Returns the headers to be rendered on the left of the grid. Should be a 2-dimensional array, where each item specifies the number
4077 * of rows it groups. In the example below we have 5 city groups, which are each part of a continent supergroup. The rowspan for each
4078 * city group refers to the number of normal grid columns that group spans, so in this case the grid would be expected to have a
4085 {header: 'England', rowspan: 5},
4086 {header: 'USA', rowspan: 3}
4092 {header: 'London', rowspan: 2},
4093 {header: 'Cambridge', rowspan: 3},
4094 {header: 'Palo Alto', rowspan: 3}
4099 * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
4100 * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
4101 * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
4102 * be the sum of all child nodes beneath this node.
4103 * Each group may specify the width it should be rendered with.
4104 * @return {Array} The row groups
4106 getRowHeaders: function() {
4107 return this.grid.leftAxis.buildHeaders();
4112 * Renders rows between start and end indexes
4113 * @param {Number} startRow Index of the first row to render
4114 * @param {Number} endRow Index of the last row to render
4116 renderRows : function(startRow, endRow) {
4117 var grid = this.grid,
4118 rows = grid.extractData(),
4119 rowCount = rows.length,
4120 templates = this.templates,
4121 renderer = grid.renderer,
4122 hasRenderer = typeof renderer == 'function',
4123 getCellCls = this.getCellCls,
4124 hasGetCellCls = typeof getCellCls == 'function',
4125 cellTemplate = templates.cell,
4126 rowTemplate = templates.row,
4129 tstyle = 'width:' + this.getGridInnerWidth() + 'px;',
4130 colBuffer, column, i;
4132 startRow = startRow || 0;
4133 endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
4135 for (i = 0; i < rowCount; i++) {
4137 colCount = row.length;
4140 rowIndex = startRow + i;
4142 //build up each column's HTML
4143 for (j = 0; j < colCount; j++) {
4146 meta.css = j === 0 ? 'x-grid3-cell-first ' : (j == (colCount - 1) ? 'x-grid3-cell-last ' : '');
4147 meta.attr = meta.cellAttr = '';
4150 if (Ext.isEmpty(meta.value)) {
4151 meta.value = ' ';
4155 meta.value = renderer(meta.value);
4158 if (hasGetCellCls) {
4159 meta.css += getCellCls(meta.value) + ' ';
4162 colBuffer[colBuffer.length] = cellTemplate.apply(meta);
4165 rowBuffer[rowBuffer.length] = rowTemplate.apply({
4168 cells : colBuffer.join(""),
4173 return rowBuffer.join("");
4177 * The master template to use when rendering the GridView. Has a default template
4178 * @property Ext.Template
4181 masterTpl: new Ext.Template(
4182 '<div class="x-grid3 x-pivotgrid" hidefocus="true">',
4183 '<div class="x-grid3-viewport">',
4184 '<div class="x-grid3-header">',
4185 '<div class="x-grid3-header-title"><span>{title}</span></div>',
4186 '<div class="x-grid3-header-inner">',
4187 '<div class="x-grid3-header-offset" style="{ostyle}"></div>',
4189 '<div class="x-clear"></div>',
4191 '<div class="x-grid3-scroller">',
4192 '<div class="x-grid3-row-headers"></div>',
4193 '<div class="x-grid3-body" style="{bstyle}">{body}</div>',
4194 '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
4197 '<div class="x-grid3-resize-marker"> </div>',
4198 '<div class="x-grid3-resize-proxy"> </div>',
4204 * Adds a gcell template to the internal templates object. This is used to render the headers in a multi-level column header.
4206 initTemplates: function() {
4207 Ext.grid.PivotGridView.superclass.initTemplates.apply(this, arguments);
4209 var templates = this.templates || {};
4210 if (!templates.gcell) {
4211 templates.gcell = new Ext.XTemplate(
4212 '<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} ' + this.colHeaderCellCls + '" style="{style}">',
4213 '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
4214 this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}',
4220 this.templates = templates;
4221 this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
4226 * Sets up the reference to the row headers element
4228 initElements: function() {
4229 Ext.grid.PivotGridView.superclass.initElements.apply(this, arguments);
4232 * @property rowHeadersEl
4234 * The element containing all row headers
4236 this.rowHeadersEl = new Ext.Element(this.scroller.child('div.x-grid3-row-headers'));
4239 * @property headerTitleEl
4241 * The element that contains the optional title (top left section of the pivot grid)
4243 this.headerTitleEl = new Ext.Element(this.mainHd.child('div.x-grid3-header-title'));
4248 * Takes row headers into account when calculating total available width
4250 getGridInnerWidth: function() {
4251 var previousWidth = Ext.grid.PivotGridView.superclass.getGridInnerWidth.apply(this, arguments);
4253 return previousWidth - this.getTotalRowHeaderWidth();
4257 * Returns the total width of all row headers as specified by {@link #getRowHeaders}
4258 * @return {Number} The total width
4260 getTotalRowHeaderWidth: function() {
4261 var headers = this.getRowHeaders(),
4262 length = headers.length,
4266 for (i = 0; i< length; i++) {
4267 total += headers[i].width;
4275 * Returns the total height of all column headers
4276 * @return {Number} The total height
4278 getTotalColumnHeaderHeight: function() {
4279 return this.getColumnHeaders().length * 21;
4284 * Slight specialisation of the GridView renderUI - just adds the row headers
4286 renderUI : function() {
4287 var templates = this.templates,
4288 innerWidth = this.getGridInnerWidth();
4290 return templates.master.apply({
4291 body : templates.body.apply({rows:' '}),
4292 ostyle: 'width:' + innerWidth + 'px',
4293 bstyle: 'width:' + innerWidth + 'px'
4299 * Make sure that the headers and rows are all sized correctly during layout
4301 onLayout: function(width, height) {
4302 Ext.grid.PivotGridView.superclass.onLayout.apply(this, arguments);
4304 var width = this.getGridInnerWidth();
4306 this.resizeColumnHeaders(width);
4307 this.resizeAllRows(width);
4311 * Refreshs the grid UI
4312 * @param {Boolean} headersToo (optional) True to also refresh the headers
4314 refresh : function(headersToo) {
4315 this.fireEvent('beforerefresh', this);
4316 this.grid.stopEditing(true);
4318 var result = this.renderBody();
4319 this.mainBody.update(result).setWidth(this.getGridInnerWidth());
4320 if (headersToo === true) {
4321 this.updateHeaders();
4322 this.updateHeaderSortState();
4324 this.processRows(0, true);
4326 this.applyEmptyText();
4327 this.fireEvent('refresh', this);
4332 * Bypasses GridView's renderHeaders as they are taken care of separately by the PivotAxis instances
4334 renderHeaders: Ext.emptyFn,
4338 * Taken care of by PivotAxis
4340 fitColumns: Ext.emptyFn,
4344 * Called on layout, ensures that the width of each column header is correct. Omitting this can lead to faulty
4345 * layouts when nested in a container.
4346 * @param {Number} width The new width
4348 resizeColumnHeaders: function(width) {
4349 var topAxis = this.grid.topAxis;
4351 if (topAxis.rendered) {
4352 topAxis.el.setWidth(width);
4358 * Sets the row header div to the correct width. Should be called after rendering and reconfiguration of headers
4360 resizeRowHeaders: function() {
4361 var rowHeaderWidth = this.getTotalRowHeaderWidth(),
4362 marginStyle = String.format("margin-left: {0}px;", rowHeaderWidth);
4364 this.rowHeadersEl.setWidth(rowHeaderWidth);
4365 this.mainBody.applyStyles(marginStyle);
4366 Ext.fly(this.innerHd).applyStyles(marginStyle);
4368 this.headerTitleEl.setWidth(rowHeaderWidth);
4369 this.headerTitleEl.setHeight(this.getTotalColumnHeaderHeight());
4374 * Resizes all rendered rows to the given width. Usually called by onLayout
4375 * @param {Number} width The new width
4377 resizeAllRows: function(width) {
4378 var rows = this.getRows(),
4379 length = rows.length,
4382 for (i = 0; i < length; i++) {
4383 Ext.fly(rows[i]).setWidth(width);
4384 Ext.fly(rows[i]).child('table').setWidth(width);
4390 * Updates the Row Headers, deferring the updating of Column Headers to GridView
4392 updateHeaders: function() {
4393 this.renderGroupRowHeaders();
4394 this.renderGroupColumnHeaders();
4399 * Renders all row header groups at all levels based on the structure fetched from {@link #getGroupRowHeaders}
4401 renderGroupRowHeaders: function() {
4402 var leftAxis = this.grid.leftAxis;
4404 this.resizeRowHeaders();
4405 leftAxis.rendered = false;
4406 leftAxis.render(this.rowHeadersEl);
4408 this.setTitle(this.title);
4412 * Sets the title text in the top left segment of the PivotGridView
4413 * @param {String} title The title
4415 setTitle: function(title) {
4416 this.headerTitleEl.child('span').dom.innerHTML = title;
4421 * Renders all column header groups at all levels based on the structure fetched from {@link #getColumnHeaders}
4423 renderGroupColumnHeaders: function() {
4424 var topAxis = this.grid.topAxis;
4426 topAxis.rendered = false;
4427 topAxis.render(this.innerHd.firstChild);
4432 * Overridden to test whether the user is hovering over a group cell, in which case we don't show the menu
4434 isMenuDisabled: function(cellIndex, el) {
4438 * @class Ext.grid.PivotAxis
4439 * @extends Ext.Component
4440 * <p>PivotAxis is a class that supports a {@link Ext.grid.PivotGrid}. Each PivotGrid contains two PivotAxis instances - the left
4441 * axis and the top axis. Each PivotAxis defines an ordered set of dimensions, each of which should correspond to a field in a
4442 * Store's Record (see {@link Ext.grid.PivotGrid} documentation for further explanation).</p>
4443 * <p>Developers should have little interaction with the PivotAxis instances directly as most of their management is performed by
4444 * the PivotGrid. An exception is the dynamic reconfiguration of axes at run time - to achieve this we use PivotAxis's
4445 * {@link #setDimensions} function and refresh the grid:</p>
4447 var pivotGrid = new Ext.grid.PivotGrid({
4448 //some PivotGrid config here
4451 //change the left axis dimensions
4452 pivotGrid.leftAxis.setDimensions([
4454 dataIndex: 'person',
4459 dataIndex: 'product',
4465 pivotGrid.view.refresh(true);
4467 * This clears the previous dimensions on the axis and redraws the grid with the new dimensions.
4469 Ext.grid.PivotAxis = Ext.extend(Ext.Component, {
4471 * @cfg {String} orientation One of 'vertical' or 'horizontal'. Defaults to horizontal
4473 orientation: 'horizontal',
4476 * @cfg {Number} defaultHeaderWidth The width to render each row header that does not have a width specified via
4477 {@link #getRowGroupHeaders}. Defaults to 80.
4479 defaultHeaderWidth: 80,
4483 * @cfg {Number} paddingWidth The amount of padding used by each cell.
4484 * TODO: From 4.x onwards this can be removed as it won't be needed. For now it is used to account for the differences between
4485 * the content box and border box measurement models
4490 * Updates the dimensions used by this axis
4491 * @param {Array} dimensions The new dimensions
4493 setDimensions: function(dimensions) {
4494 this.dimensions = dimensions;
4499 * Builds the html table that contains the dimensions for this axis. This branches internally between vertical
4500 * and horizontal orientations because the table structure is slightly different in each case
4502 onRender: function(ct, position) {
4503 var rows = this.orientation == 'horizontal'
4504 ? this.renderHorizontalRows()
4505 : this.renderVerticalRows();
4507 this.el = Ext.DomHelper.overwrite(ct.dom, {tag: 'table', cn: rows}, true);
4512 * Specialised renderer for horizontal oriented axes
4513 * @return {Object} The HTML Domspec for a horizontal oriented axis
4515 renderHorizontalRows: function() {
4516 var headers = this.buildHeaders(),
4517 rowCount = headers.length,
4519 cells, cols, colCount, i, j;
4521 for (i = 0; i < rowCount; i++) {
4523 cols = headers[i].items;
4524 colCount = cols.length;
4526 for (j = 0; j < colCount; j++) {
4529 html: cols[j].header,
4530 colspan: cols[j].span
4545 * Specialised renderer for vertical oriented axes
4546 * @return {Object} The HTML Domspec for a vertical oriented axis
4548 renderVerticalRows: function() {
4549 var headers = this.buildHeaders(),
4550 colCount = headers.length,
4553 rowCount, col, row, colWidth, i, j;
4555 for (i = 0; i < colCount; i++) {
4557 colWidth = col.width || 80;
4558 rowCount = col.items.length;
4560 for (j = 0; j < rowCount; j++) {
4563 rowCells[row.start] = rowCells[row.start] || [];
4564 rowCells[row.start].push({
4568 width : Ext.isBorderBox ? colWidth : colWidth - this.paddingWidth
4573 rowCount = rowCells.length;
4574 for (i = 0; i < rowCount; i++) {
4586 * Returns the set of all unique tuples based on the bound store and dimension definitions.
4587 * Internally we construct a new, temporary store to make use of the multi-sort capabilities of Store. In
4588 * 4.x this functionality should have been moved to MixedCollection so this step should not be needed.
4589 * @return {Array} All unique tuples
4591 getTuples: function() {
4592 var newStore = new Ext.data.Store({});
4594 newStore.data = this.store.data.clone();
4595 newStore.fields = this.store.fields;
4598 dimensions = this.dimensions,
4599 length = dimensions.length,
4602 for (i = 0; i < length; i++) {
4604 field : dimensions[i].dataIndex,
4605 direction: dimensions[i].direction || 'ASC'
4609 newStore.sort(sorters);
4611 var records = newStore.data.items,
4614 recData, hash, info, data, key;
4616 length = records.length;
4618 for (i = 0; i < length; i++) {
4619 info = this.getRecordInfo(records[i]);
4624 hash += data[key] + '---';
4627 if (hashes.indexOf(hash) == -1) {
4641 getRecordInfo: function(record) {
4642 var dimensions = this.dimensions,
4643 length = dimensions.length,
4645 dimension, dataIndex, i;
4647 //get an object containing just the data we are interested in based on the configured dimensions
4648 for (i = 0; i < length; i++) {
4649 dimension = dimensions[i];
4650 dataIndex = dimension.dataIndex;
4652 data[dataIndex] = record.get(dataIndex);
4655 //creates a specialised matcher function for a given tuple. The returned function will return
4656 //true if the record passed to it matches the dataIndex values of each dimension in this axis
4657 var createMatcherFunction = function(data) {
4658 return function(record) {
4659 for (var dataIndex in data) {
4660 if (record.get(dataIndex) != data[dataIndex]) {
4671 matcher: createMatcherFunction(data)
4677 * Uses the calculated set of tuples to build an array of headers that can be rendered into a table using rowspan or
4678 * colspan. Basically this takes the set of tuples and spans any cells that run into one another, so if we had dimensions
4679 * of Person and Product and several tuples containing different Products for the same Person, those Products would be
4681 * @return {Array} The headers
4683 buildHeaders: function() {
4684 var tuples = this.getTuples(),
4685 rowCount = tuples.length,
4686 dimensions = this.dimensions,
4687 colCount = dimensions.length,
4689 tuple, rows, currentHeader, previousHeader, span, start, isLast, changed, i, j;
4691 for (i = 0; i < colCount; i++) {
4692 dimension = dimensions[i];
4697 for (j = 0; j < rowCount; j++) {
4699 isLast = j == (rowCount - 1);
4700 currentHeader = tuple.data[dimension.dataIndex];
4703 * 'changed' indicates that we need to create a new cell. This should be true whenever the cell
4704 * above (previousHeader) is different from this cell, or when the cell on the previous dimension
4705 * changed (e.g. if the current dimension is Product and the previous was Person, we need to start
4706 * a new cell if Product is the same but Person changed, so we check the previous dimension and tuple)
4708 changed = previousHeader != undefined && previousHeader != currentHeader;
4709 if (i > 0 && j > 0) {
4710 changed = changed || tuple.data[dimensions[i-1].dataIndex] != tuples[j-1].data[dimensions[i-1].dataIndex];
4715 header: previousHeader,
4726 header: currentHeader,
4735 previousHeader = currentHeader;
4741 width: dimension.width || this.defaultHeaderWidth
4744 previousHeader = undefined;
4751 // This is a support class used internally by the Grid components
4752 Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
4755 constructor : function(grid, hd, hd2){
4757 this.view = grid.getView();
4758 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
4759 Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
4761 this.setHandleElId(Ext.id(hd));
4762 this.setOuterHandleElId(Ext.id(hd2));
4764 this.scroll = false;
4767 getDragData : function(e){
4768 var t = Ext.lib.Event.getTarget(e),
4769 h = this.view.findHeaderCell(t);
4771 return {ddel: h.firstChild, header:h};
4776 onInitDrag : function(e){
4777 // keep the value here so we can restore it;
4778 this.dragHeadersDisabled = this.view.headersDisabled;
4779 this.view.headersDisabled = true;
4780 var clone = this.dragData.ddel.cloneNode(true);
4781 clone.id = Ext.id();
4782 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
4783 this.proxy.update(clone);
4787 afterValidDrop : function(){
4788 this.completeDrop();
4791 afterInvalidDrop : function(){
4792 this.completeDrop();
4795 completeDrop: function(){
4797 disabled = this.dragHeadersDisabled;
4798 setTimeout(function(){
4799 v.headersDisabled = disabled;
4805 // This is a support class used internally by the Grid components
4806 Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
4807 proxyOffsets : [-4, -9],
4808 fly: Ext.Element.fly,
4810 constructor : function(grid, hd, hd2){
4812 this.view = grid.getView();
4813 // split the proxies so they don't interfere with mouse events
4814 this.proxyTop = Ext.DomHelper.append(document.body, {
4815 cls:"col-move-top", html:" "
4817 this.proxyBottom = Ext.DomHelper.append(document.body, {
4818 cls:"col-move-bottom", html:" "
4820 this.proxyTop.hide = this.proxyBottom.hide = function(){
4821 this.setLeftTop(-100,-100);
4822 this.setStyle("visibility", "hidden");
4824 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
4825 // temporarily disabled
4826 //Ext.dd.ScrollManager.register(this.view.scroller.dom);
4827 Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
4830 getTargetFromEvent : function(e){
4831 var t = Ext.lib.Event.getTarget(e),
4832 cindex = this.view.findCellIndex(t);
4833 if(cindex !== false){
4834 return this.view.getHeaderCell(cindex);
4838 nextVisible : function(h){
4839 var v = this.view, cm = this.grid.colModel;
4842 if(!cm.isHidden(v.getCellIndex(h))){
4850 prevVisible : function(h){
4851 var v = this.view, cm = this.grid.colModel;
4854 if(!cm.isHidden(v.getCellIndex(h))){
4862 positionIndicator : function(h, n, e){
4863 var x = Ext.lib.Event.getPageX(e),
4864 r = Ext.lib.Dom.getRegion(n.firstChild),
4867 py = r.top + this.proxyOffsets[1];
4868 if((r.right - x) <= (r.right-r.left)/2){
4869 px = r.right+this.view.borderWidth;
4876 if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
4880 px += this.proxyOffsets[0];
4881 this.proxyTop.setLeftTop(px, py);
4882 this.proxyTop.show();
4883 if(!this.bottomOffset){
4884 this.bottomOffset = this.view.mainHd.getHeight();
4886 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
4887 this.proxyBottom.show();
4891 onNodeEnter : function(n, dd, e, data){
4892 if(data.header != n){
4893 this.positionIndicator(data.header, n, e);
4897 onNodeOver : function(n, dd, e, data){
4899 if(data.header != n){
4900 result = this.positionIndicator(data.header, n, e);
4903 this.proxyTop.hide();
4904 this.proxyBottom.hide();
4906 return result ? this.dropAllowed : this.dropNotAllowed;
4909 onNodeOut : function(n, dd, e, data){
4910 this.proxyTop.hide();
4911 this.proxyBottom.hide();
4914 onNodeDrop : function(n, dd, e, data){
4915 var h = data.header;
4917 var cm = this.grid.colModel,
4918 x = Ext.lib.Event.getPageX(e),
4919 r = Ext.lib.Dom.getRegion(n.firstChild),
4920 pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before",
4921 oldIndex = this.view.getCellIndex(h),
4922 newIndex = this.view.getCellIndex(n);
4926 if(oldIndex < newIndex){
4929 cm.moveColumn(oldIndex, newIndex);
4936 Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
4938 constructor : function(grid, hd){
4939 Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
4940 this.proxy.el.addClass('x-grid3-col-dd');
4943 handleMouseDown : function(e){
4946 callHandleMouseDown : function(e){
4947 Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
4950 // This is a support class used internally by the Grid components
4951 Ext.grid.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
4952 fly: Ext.Element.fly,
4954 constructor : function(grid, hd, hd2){
4956 this.view = grid.getView();
4957 this.proxy = this.view.resizeProxy;
4958 Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
4959 "gridSplitters" + this.grid.getGridEl().id, {
4960 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
4962 this.setHandleElId(Ext.id(hd));
4963 this.setOuterHandleElId(Ext.id(hd2));
4964 this.scroll = false;
4967 b4StartDrag : function(x, y){
4968 this.view.headersDisabled = true;
4969 this.proxy.setHeight(this.view.mainWrap.getHeight());
4970 var w = this.cm.getColumnWidth(this.cellIndex);
4971 var minw = Math.max(w-this.grid.minColumnWidth, 0);
4972 this.resetConstraints();
4973 this.setXConstraint(minw, 1000);
4974 this.setYConstraint(0, 0);
4975 this.minX = x - minw;
4976 this.maxX = x + 1000;
4978 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
4982 handleMouseDown : function(e){
4983 var ev = Ext.EventObject.setEvent(e);
4984 var t = this.fly(ev.getTarget());
4985 if(t.hasClass("x-grid-split")){
4986 this.cellIndex = this.view.getCellIndex(t.dom);
4988 this.cm = this.grid.colModel;
4989 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
4990 Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
4995 endDrag : function(e){
4996 this.view.headersDisabled = false;
4997 var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e));
4998 var diff = endX - this.startPos;
4999 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
5002 autoOffset : function(){
5006 * @class Ext.grid.GridDragZone
5007 * @extends Ext.dd.DragZone
5008 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of two of the
5009 * template methods of DragZone to enable dragging of the selected rows of a GridPanel.</p>
5010 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's template method implementations of
5011 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
5012 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop}</p> are able
5013 * to process the {@link #getDragData data} which is provided.
5015 Ext.grid.GridDragZone = function(grid, config){
5016 this.view = grid.getView();
5017 Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
5018 this.scroll = false;
5020 this.ddel = document.createElement('div');
5021 this.ddel.className = 'x-grid-dd-wrap';
5024 Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, {
5028 * <p>The provided implementation of the getDragData method which collects the data to be dragged from the GridPanel on mousedown.</p>
5029 * <p>This data is available for processing in the {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
5030 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} methods of a cooperating {@link Ext.dd.DropZone DropZone}.</p>
5031 * <p>The data object contains the following properties:<ul>
5032 * <li><b>grid</b> : Ext.Grid.GridPanel<div class="sub-desc">The GridPanel from which the data is being dragged.</div></li>
5033 * <li><b>ddel</b> : htmlElement<div class="sub-desc">An htmlElement which provides the "picture" of the data being dragged.</div></li>
5034 * <li><b>rowIndex</b> : Number<div class="sub-desc">The index of the row which receieved the mousedown gesture which triggered the drag.</div></li>
5035 * <li><b>selections</b> : Array<div class="sub-desc">An Array of the selected Records which are being dragged from the GridPanel.</div></li>
5038 getDragData : function(e){
5039 var t = Ext.lib.Event.getTarget(e);
5040 var rowIndex = this.view.findRowIndex(t);
5041 if(rowIndex !== false){
5042 var sm = this.grid.selModel;
5043 if(!sm.isSelected(rowIndex) || e.hasModifier()){
5044 sm.handleMouseDown(this.grid, rowIndex, e);
5046 return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
5052 * <p>The provided implementation of the onInitDrag method. Sets the <tt>innerHTML</tt> of the drag proxy which provides the "picture"
5053 * of the data being dragged.</p>
5054 * <p>The <tt>innerHTML</tt> data is found by calling the owning GridPanel's {@link Ext.grid.GridPanel#getDragDropText getDragDropText}.</p>
5056 onInitDrag : function(e){
5057 var data = this.dragData;
5058 this.ddel.innerHTML = this.grid.getDragDropText();
5059 this.proxy.update(this.ddel);
5064 * An empty immplementation. Implement this to provide behaviour after a repair of an invalid drop. An implementation might highlight
5065 * the selected rows to show that they have not been dragged.
5067 afterRepair : function(){
5068 this.dragging = false;
5072 * <p>An empty implementation. Implement this to provide coordinates for the drag proxy to slide back to after an invalid drop.</p>
5073 * <p>Called before a repair of an invalid drop to get the XY to animate to.</p>
5074 * @param {EventObject} e The mouse up event
5075 * @return {Array} The xy location (e.g. [100, 200])
5077 getRepairXY : function(e, data){
5081 onEndDrag : function(data, e){
5085 onValidDrop : function(dd, e, id){
5090 beforeInvalidDrop : function(e, id){
5095 * @class Ext.grid.ColumnModel
5096 * @extends Ext.util.Observable
5097 * <p>After the data has been read into the client side cache (<b>{@link Ext.data.Store Store}</b>),
5098 * the ColumnModel is used to configure how and what parts of that data will be displayed in the
5099 * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation
5100 * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.</p>
5101 * <p>Data is mapped into the store's records and then indexed into the ColumnModel using the
5102 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt>:</p>
5104 {data source} == mapping ==> {data store} == <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> ==> {ColumnModel}
5106 * <p>Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a
5107 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt> to specify how the data within
5108 * each record in the store is indexed into the ColumnModel.</p>
5109 * <p>There are two ways to initialize the ColumnModel class:</p>
5110 * <p><u>Initialization Method 1: an Array</u></p>
5112 var colModel = new Ext.grid.ColumnModel([
5113 { header: "Ticker", width: 60, sortable: true},
5114 { header: "Company Name", width: 150, sortable: true, id: 'company'},
5115 { header: "Market Cap.", width: 100, sortable: true},
5116 { header: "$ Sales", width: 100, sortable: true, renderer: money},
5117 { header: "Employees", width: 100, sortable: true, resizable: false}
5120 * <p>The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration
5121 * objects to define the initial layout / display of the columns in the Grid. The order of each
5122 * {@link Ext.grid.Column} column configuration object within the specified Array defines the initial
5123 * order of the column display. A Column's display may be initially hidden using the
5124 * <tt>{@link Ext.grid.Column#hidden hidden}</tt></b> config property (and then shown using the column
5125 * header menu). Fields that are not included in the ColumnModel will not be displayable at all.</p>
5126 * <p>How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the
5127 * {@link Ext.data.Store Store} the column draws its data from is configured through the
5128 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b>. If the
5129 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> is not explicitly defined (as shown in the
5130 * example above) it will use the column configuration's index in the Array as the index.</p>
5131 * <p>See <b><tt>{@link Ext.grid.Column}</tt></b> for additional configuration options for each column.</p>
5132 * <p><u>Initialization Method 2: an Object</u></p>
5133 * <p>In order to use configuration options from <tt>Ext.grid.ColumnModel</tt>, an Object may be used to
5134 * initialize the ColumnModel. The column configuration Array will be specified in the <tt><b>{@link #columns}</b></tt>
5135 * config property. The <tt><b>{@link #defaults}</b></tt> config property can be used to apply defaults
5136 * for all columns, e.g.:</p><pre><code>
5137 var colModel = new Ext.grid.ColumnModel({
5139 { header: "Ticker", width: 60, menuDisabled: false},
5140 { header: "Company Name", width: 150, id: 'company'},
5141 { header: "Market Cap."},
5142 { header: "$ Sales", renderer: money},
5143 { header: "Employees", resizable: false}
5151 {@link #hiddenchange}: function(cm, colIndex, hidden) {
5152 saveConfig(colIndex, hidden);
5157 * <p>In both examples above, the ability to apply a CSS class to all cells in a column (including the
5158 * header) is demonstrated through the use of the <b><tt>{@link Ext.grid.Column#id id}</tt></b> config
5159 * option. This column could be styled by including the following css:</p><pre><code>
5160 //add this css *after* the core css is loaded
5161 .x-grid3-td-company {
5162 color: red; // entire column will have red font
5164 // modify the header row only, adding an icon to the column header
5165 .x-grid3-hd-company {
5166 background: transparent
5167 url(../../resources/images/icons/silk/building.png)
5168 no-repeat 3px 3px ! important;
5172 * Note that the "Company Name" column could be specified as the
5173 * <b><tt>{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></b>.
5175 * @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify
5176 * a configuration Object (see introductory section discussion utilizing Initialization Method 2 above).
5178 Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
5180 * @cfg {Number} defaultWidth (optional) The width of columns which have no <tt>{@link #width}</tt>
5181 * specified (defaults to <tt>100</tt>). This property shall preferably be configured through the
5182 * <tt><b>{@link #defaults}</b></tt> config property.
5187 * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no
5188 * sortable specified (defaults to <tt>false</tt>). This property shall preferably be configured
5189 * through the <tt><b>{@link #defaults}</b></tt> config property.
5191 defaultSortable: false,
5194 * @cfg {Array} columns An Array of object literals. The config options defined by
5195 * <b>{@link Ext.grid.Column}</b> are the options which may appear in the object literal for each
5196 * individual column definition.
5200 * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column}
5201 * configuration options to all <tt><b>{@link #columns}</b></tt>. Configuration options specified with
5202 * individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>.
5205 constructor : function(config) {
5207 * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
5208 * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
5213 if (config.columns) {
5214 Ext.apply(this, config);
5215 this.setConfig(config.columns, true);
5217 this.setConfig(config, true);
5222 * @event widthchange
5223 * Fires when the width of a column is programmaticially changed using
5224 * <code>{@link #setColumnWidth}</code>.
5225 * Note internal resizing suppresses the event from firing. See also
5226 * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>.
5227 * @param {ColumnModel} this
5228 * @param {Number} columnIndex The column index
5229 * @param {Number} newWidth The new width
5234 * @event headerchange
5235 * Fires when the text of a header changes.
5236 * @param {ColumnModel} this
5237 * @param {Number} columnIndex The column index
5238 * @param {String} newText The new header text
5243 * @event hiddenchange
5244 * Fires when a column is hidden or "unhidden".
5245 * @param {ColumnModel} this
5246 * @param {Number} columnIndex The column index
5247 * @param {Boolean} hidden true if hidden, false otherwise
5252 * @event columnmoved
5253 * Fires when a column is moved.
5254 * @param {ColumnModel} this
5255 * @param {Number} oldIndex
5256 * @param {Number} newIndex
5261 * @event configchange
5262 * Fires when the configuration is changed
5263 * @param {ColumnModel} this
5268 Ext.grid.ColumnModel.superclass.constructor.call(this);
5272 * Returns the id of the column at the specified index.
5273 * @param {Number} index The column index
5274 * @return {String} the id
5276 getColumnId : function(index) {
5277 return this.config[index].id;
5280 getColumnAt : function(index) {
5281 return this.config[index];
5285 * <p>Reconfigures this column model according to the passed Array of column definition objects.
5286 * For a description of the individual properties of a column definition object, see the
5287 * <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p>
5288 * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel}
5289 * using this ColumnModel will listen for this event and refresh its UI automatically.</p>
5290 * @param {Array} config Array of Column definition objects.
5291 * @param {Boolean} initial Specify <tt>true</tt> to bypass cleanup which deletes the <tt>totalWidth</tt>
5292 * and destroys existing editors.
5294 setConfig : function(config, initial) {
5297 if (!initial) { // cleanup
5298 delete this.totalWidth;
5300 for (i = 0, len = this.config.length; i < len; i++) {
5304 //check here, in case we have a special column like a CheckboxSelectionModel
5310 // backward compatibility
5311 this.defaults = Ext.apply({
5312 width: this.defaultWidth,
5313 sortable: this.defaultSortable
5316 this.config = config;
5319 for (i = 0, len = config.length; i < len; i++) {
5320 c = Ext.applyIf(config[i], this.defaults);
5322 // if no id, create one using column's ordinal position
5323 if (Ext.isEmpty(c.id)) {
5328 var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
5333 this.lookup[c.id] = c;
5337 this.fireEvent('configchange', this);
5342 * Returns the column for a specified id.
5343 * @param {String} id The column id
5344 * @return {Object} the column
5346 getColumnById : function(id) {
5347 return this.lookup[id];
5351 * Returns the index for a specified column id.
5352 * @param {String} id The column id
5353 * @return {Number} the index, or -1 if not found
5355 getIndexById : function(id) {
5356 for (var i = 0, len = this.config.length; i < len; i++) {
5357 if (this.config[i].id == id) {
5365 * Moves a column from one position to another.
5366 * @param {Number} oldIndex The index of the column to move.
5367 * @param {Number} newIndex The position at which to reinsert the coolumn.
5369 moveColumn : function(oldIndex, newIndex) {
5370 var config = this.config,
5371 c = config[oldIndex];
5373 config.splice(oldIndex, 1);
5374 config.splice(newIndex, 0, c);
5375 this.dataMap = null;
5376 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5380 * Returns the number of columns.
5381 * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.
5384 getColumnCount : function(visibleOnly) {
5385 var length = this.config.length,
5389 if (visibleOnly === true) {
5390 for (i = 0; i < length; i++) {
5391 if (!this.isHidden(i)) {
5403 * Returns the column configs that return true by the passed function that is called
5404 * with (columnConfig, index)
5406 // returns an array of column config objects for all hidden columns
5407 var columns = grid.getColumnModel().getColumnsBy(function(c){
5411 * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must
5412 * return <code>true</code> if the column is to be included in the returned Array.
5413 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function
5414 * is executed. Defaults to this ColumnModel.
5415 * @return {Array} result
5417 getColumnsBy : function(fn, scope) {
5418 var config = this.config,
5419 length = config.length,
5423 for (i = 0; i < length; i++){
5426 if (fn.call(scope || this, c, i) === true) {
5427 result[result.length] = c;
5435 * Returns true if the specified column is sortable.
5436 * @param {Number} col The column index
5439 isSortable : function(col) {
5440 return !!this.config[col].sortable;
5444 * Returns true if the specified column menu is disabled.
5445 * @param {Number} col The column index
5448 isMenuDisabled : function(col) {
5449 return !!this.config[col].menuDisabled;
5453 * Returns the rendering (formatting) function defined for the column.
5454 * @param {Number} col The column index.
5455 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5457 getRenderer : function(col) {
5458 return this.config[col].renderer || Ext.grid.ColumnModel.defaultRenderer;
5461 getRendererScope : function(col) {
5462 return this.config[col].scope;
5466 * Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
5467 * default formatting functions.
5468 * @param {Number} col The column index
5469 * @param {Function} fn The function to use to process the cell's raw data
5470 * to return HTML markup for the grid view. The render function is called with
5471 * the following parameters:<ul>
5472 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
5473 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
5474 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
5475 * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell
5476 * (e.g. 'style="color:red;"').</p></li></ul></p></li>
5477 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was extracted.</p></li>
5478 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
5479 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
5480 * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record was extracted.</p></li></ul>
5482 setRenderer : function(col, fn) {
5483 this.config[col].renderer = fn;
5487 * Returns the width for the specified column.
5488 * @param {Number} col The column index
5491 getColumnWidth : function(col) {
5492 var width = this.config[col].width;
5493 if(typeof width != 'number'){
5494 width = this.defaultWidth;
5500 * Sets the width for a column.
5501 * @param {Number} col The column index
5502 * @param {Number} width The new width
5503 * @param {Boolean} suppressEvent True to suppress firing the <code>{@link #widthchange}</code>
5504 * event. Defaults to false.
5506 setColumnWidth : function(col, width, suppressEvent) {
5507 this.config[col].width = width;
5508 this.totalWidth = null;
5510 if (!suppressEvent) {
5511 this.fireEvent("widthchange", this, col, width);
5516 * Returns the total width of all columns.
5517 * @param {Boolean} includeHidden True to include hidden column widths
5520 getTotalWidth : function(includeHidden) {
5521 if (!this.totalWidth) {
5522 this.totalWidth = 0;
5523 for (var i = 0, len = this.config.length; i < len; i++) {
5524 if (includeHidden || !this.isHidden(i)) {
5525 this.totalWidth += this.getColumnWidth(i);
5529 return this.totalWidth;
5533 * Returns the header for the specified column.
5534 * @param {Number} col The column index
5537 getColumnHeader : function(col) {
5538 return this.config[col].header;
5542 * Sets the header for a column.
5543 * @param {Number} col The column index
5544 * @param {String} header The new header
5546 setColumnHeader : function(col, header) {
5547 this.config[col].header = header;
5548 this.fireEvent("headerchange", this, col, header);
5552 * Returns the tooltip for the specified column.
5553 * @param {Number} col The column index
5556 getColumnTooltip : function(col) {
5557 return this.config[col].tooltip;
5560 * Sets the tooltip for a column.
5561 * @param {Number} col The column index
5562 * @param {String} tooltip The new tooltip
5564 setColumnTooltip : function(col, tooltip) {
5565 this.config[col].tooltip = tooltip;
5569 * Returns the dataIndex for the specified column.
5571 // Get field name for the column
5572 var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
5574 * @param {Number} col The column index
5575 * @return {String} The column's dataIndex
5577 getDataIndex : function(col) {
5578 return this.config[col].dataIndex;
5582 * Sets the dataIndex for a column.
5583 * @param {Number} col The column index
5584 * @param {String} dataIndex The new dataIndex
5586 setDataIndex : function(col, dataIndex) {
5587 this.config[col].dataIndex = dataIndex;
5591 * Finds the index of the first matching column for the given dataIndex.
5592 * @param {String} col The dataIndex to find
5593 * @return {Number} The column index, or -1 if no match was found
5595 findColumnIndex : function(dataIndex) {
5596 var c = this.config;
5597 for(var i = 0, len = c.length; i < len; i++){
5598 if(c[i].dataIndex == dataIndex){
5606 * Returns true if the cell is editable.
5608 var store = new Ext.data.Store({...});
5609 var colModel = new Ext.grid.ColumnModel({
5611 isCellEditable: function(col, row) {
5612 var record = store.getAt(row);
5613 if (record.get('readonly')) { // replace with your condition
5616 return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
5619 var grid = new Ext.grid.GridPanel({
5625 * @param {Number} colIndex The column index
5626 * @param {Number} rowIndex The row index
5629 isCellEditable : function(colIndex, rowIndex) {
5630 var c = this.config[colIndex],
5634 return !!(ed || (!Ext.isDefined(ed) && c.editor));
5638 * Returns the editor defined for the cell/column.
5639 * @param {Number} colIndex The column index
5640 * @param {Number} rowIndex The row index
5641 * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap
5642 * the {@link Ext.form.Field Field} used to edit the cell.
5644 getCellEditor : function(colIndex, rowIndex) {
5645 return this.config[colIndex].getCellEditor(rowIndex);
5649 * Sets if a column is editable.
5650 * @param {Number} col The column index
5651 * @param {Boolean} editable True if the column is editable
5653 setEditable : function(col, editable) {
5654 this.config[col].editable = editable;
5658 * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#hidden hidden}</code>,
5659 * <tt>false</tt> otherwise.
5660 * @param {Number} colIndex The column index
5663 isHidden : function(colIndex) {
5664 return !!this.config[colIndex].hidden; // ensure returns boolean
5668 * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#fixed fixed}</code>,
5669 * <tt>false</tt> otherwise.
5670 * @param {Number} colIndex The column index
5673 isFixed : function(colIndex) {
5674 return !!this.config[colIndex].fixed;
5678 * Returns true if the column can be resized
5681 isResizable : function(colIndex) {
5682 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5686 * Sets if a column is hidden.
5688 myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
5690 * @param {Number} colIndex The column index
5691 * @param {Boolean} hidden True if the column is hidden
5693 setHidden : function(colIndex, hidden) {
5694 var c = this.config[colIndex];
5695 if(c.hidden !== hidden){
5697 this.totalWidth = null;
5698 this.fireEvent("hiddenchange", this, colIndex, hidden);
5703 * Sets the editor for a column and destroys the prior editor.
5704 * @param {Number} col The column index
5705 * @param {Object} editor The editor object
5707 setEditor : function(col, editor) {
5708 this.config[col].setEditor(editor);
5712 * Destroys this column model by purging any event listeners. Destroys and dereferences all Columns.
5714 destroy : function() {
5715 var length = this.config.length,
5718 for (; i < length; i++){
5719 this.config[i].destroy(); // Column's destroy encapsulates all cleanup.
5723 this.purgeListeners();
5728 * Setup any saved state for the column, ensures that defaults are applied.
5730 setState : function(col, state) {
5731 state = Ext.applyIf(state, this.defaults);
5732 Ext.apply(this.config[col], state);
5737 Ext.grid.ColumnModel.defaultRenderer = function(value) {
5738 if (typeof value == "string" && value.length < 1) {
5743 * @class Ext.grid.AbstractSelectionModel
5744 * @extends Ext.util.Observable
5745 * Abstract base class for grid SelectionModels. It provides the interface that should be
5746 * implemented by descendant classes. This class should not be directly instantiated.
5749 Ext.grid.AbstractSelectionModel = Ext.extend(Ext.util.Observable, {
5751 * The GridPanel for which this SelectionModel is handling selection. Read-only.
5756 constructor : function(){
5757 this.locked = false;
5758 Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);
5761 /** @ignore Called by the grid automatically. Do not call directly. */
5762 init : function(grid){
5764 if(this.lockOnInit){
5765 delete this.lockOnInit;
5766 this.locked = false;
5773 * Locks the selections.
5778 // If the grid has been set, then the view is already initialized.
5783 beforerefresh: this.sortUnLock,
5784 refresh: this.sortLock
5787 this.lockOnInit = true;
5792 // set the lock states before and after a view refresh
5793 sortLock : function() {
5797 // set the lock states before and after a view refresh
5798 sortUnLock : function() {
5799 this.locked = false;
5803 * Unlocks the selections.
5805 unlock : function(){
5807 this.locked = false;
5811 // If the grid has been set, then the view is already initialized.
5814 gv.un('beforerefresh', this.sortUnLock, this);
5815 gv.un('refresh', this.sortLock, this);
5817 delete this.lockOnInit;
5823 * Returns true if the selections are locked.
5826 isLocked : function(){
5830 destroy: function(){
5832 this.purgeListeners();
5835 * @class Ext.grid.RowSelectionModel
5836 * @extends Ext.grid.AbstractSelectionModel
5837 * The default SelectionModel used by {@link Ext.grid.GridPanel}.
5838 * It supports multiple selections and keyboard selection/navigation. The objects stored
5839 * as selections and returned by {@link #getSelected}, and {@link #getSelections} are
5840 * the {@link Ext.data.Record Record}s which provide the data for the selected rows.
5842 * @param {Object} config
5844 Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
5846 * @cfg {Boolean} singleSelect
5847 * <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
5848 * allowing multiple selections)
5850 singleSelect : false,
5852 constructor : function(config){
5853 Ext.apply(this, config);
5854 this.selections = new Ext.util.MixedCollection(false, function(o){
5859 this.lastActive = false;
5863 * @event selectionchange
5864 * Fires when the selection changes
5865 * @param {SelectionModel} this
5869 * @event beforerowselect
5870 * Fires before a row is selected, return false to cancel the selection.
5871 * @param {SelectionModel} this
5872 * @param {Number} rowIndex The index to be selected
5873 * @param {Boolean} keepExisting False if other selections will be cleared
5874 * @param {Record} record The record to be selected
5879 * Fires when a row is selected.
5880 * @param {SelectionModel} this
5881 * @param {Number} rowIndex The selected index
5882 * @param {Ext.data.Record} r The selected record
5886 * @event rowdeselect
5887 * Fires when a row is deselected. To prevent deselection
5888 * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
5889 * @param {SelectionModel} this
5890 * @param {Number} rowIndex
5891 * @param {Record} record
5895 Ext.grid.RowSelectionModel.superclass.constructor.call(this);
5899 * @cfg {Boolean} moveEditorOnEnter
5900 * <tt>false</tt> to turn off moving the editor to the next row down when the enter key is pressed
5901 * or the next row up when shift + enter keys are pressed.
5904 initEvents : function(){
5906 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
5907 this.grid.on('rowmousedown', this.handleMouseDown, this);
5910 this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
5911 up: this.onKeyPress,
5912 down: this.onKeyPress,
5916 this.grid.getView().on({
5918 refresh: this.onRefresh,
5919 rowupdated: this.onRowUpdated,
5920 rowremoved: this.onRemove
5924 onKeyPress : function(e, name){
5925 var up = name == 'up',
5926 method = up ? 'selectPrevious' : 'selectNext',
5929 if(!e.shiftKey || this.singleSelect){
5930 this[method](false);
5931 }else if(this.last !== false && this.lastActive !== false){
5933 this.selectRange(this.last, this.lastActive + add);
5934 this.grid.getView().focusRow(this.lastActive);
5939 this.selectFirstRow();
5944 onRefresh : function(){
5945 var ds = this.grid.store,
5946 s = this.getSelections(),
5952 this.clearSelections(true);
5953 for(; i < len; i++){
5955 if((index = ds.indexOfId(r.id)) != -1){
5956 this.selectRow(index, true);
5959 if(s.length != this.selections.getCount()){
5960 this.fireEvent('selectionchange', this);
5962 this.silent = false;
5966 onRemove : function(v, index, r){
5967 if(this.selections.remove(r) !== false){
5968 this.fireEvent('selectionchange', this);
5973 onRowUpdated : function(v, index, r){
5974 if(this.isSelected(r)){
5975 v.onRowSelect(index);
5981 * @param {Array} records The records to select
5982 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
5984 selectRecords : function(records, keepExisting){
5986 this.clearSelections();
5988 var ds = this.grid.store,
5990 len = records.length;
5991 for(; i < len; i++){
5992 this.selectRow(ds.indexOf(records[i]), true);
5997 * Gets the number of selected rows.
6000 getCount : function(){
6001 return this.selections.length;
6005 * Selects the first row in the grid.
6007 selectFirstRow : function(){
6012 * Select the last row.
6013 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
6015 selectLastRow : function(keepExisting){
6016 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
6020 * Selects the row immediately following the last selected row.
6021 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
6022 * @return {Boolean} <tt>true</tt> if there is a next row, else <tt>false</tt>
6024 selectNext : function(keepExisting){
6026 this.selectRow(this.last+1, keepExisting);
6027 this.grid.getView().focusRow(this.last);
6034 * Selects the row that precedes the last selected row.
6035 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
6036 * @return {Boolean} <tt>true</tt> if there is a previous row, else <tt>false</tt>
6038 selectPrevious : function(keepExisting){
6039 if(this.hasPrevious()){
6040 this.selectRow(this.last-1, keepExisting);
6041 this.grid.getView().focusRow(this.last);
6048 * Returns true if there is a next record to select
6051 hasNext : function(){
6052 return this.last !== false && (this.last+1) < this.grid.store.getCount();
6056 * Returns true if there is a previous record to select
6059 hasPrevious : function(){
6065 * Returns the selected records
6066 * @return {Array} Array of selected records
6068 getSelections : function(){
6069 return [].concat(this.selections.items);
6073 * Returns the first selected record.
6076 getSelected : function(){
6077 return this.selections.itemAt(0);
6081 * Calls the passed function with each selection. If the function returns
6082 * <tt>false</tt>, iteration is stopped and this function returns
6083 * <tt>false</tt>. Otherwise it returns <tt>true</tt>.
6084 * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}.
6085 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel.
6086 * @return {Boolean} true if all selections were iterated
6088 each : function(fn, scope){
6089 var s = this.getSelections(),
6093 for(; i < len; i++){
6094 if(fn.call(scope || this, s[i], i) === false){
6102 * Clears all selections if the selection model
6103 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
6104 * @param {Boolean} fast (optional) <tt>true</tt> to bypass the
6105 * conditional checks and events described in {@link #deselectRow}.
6107 clearSelections : function(fast){
6108 if(this.isLocked()){
6112 var ds = this.grid.store,
6113 s = this.selections;
6115 this.deselectRow(ds.indexOfId(r.id));
6119 this.selections.clear();
6126 * Selects all rows if the selection model
6127 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
6129 selectAll : function(){
6130 if(this.isLocked()){
6133 this.selections.clear();
6134 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
6135 this.selectRow(i, true);
6140 * Returns <tt>true</tt> if there is a selection.
6143 hasSelection : function(){
6144 return this.selections.length > 0;
6148 * Returns <tt>true</tt> if the specified row is selected.
6149 * @param {Number/Record} index The record or index of the record to check
6152 isSelected : function(index){
6153 var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
6154 return (r && this.selections.key(r.id) ? true : false);
6158 * Returns <tt>true</tt> if the specified record id is selected.
6159 * @param {String} id The id of record to check
6162 isIdSelected : function(id){
6163 return (this.selections.key(id) ? true : false);
6167 handleMouseDown : function(g, rowIndex, e){
6168 if(e.button !== 0 || this.isLocked()){
6171 var view = this.grid.getView();
6172 if(e.shiftKey && !this.singleSelect && this.last !== false){
6173 var last = this.last;
6174 this.selectRange(last, rowIndex, e.ctrlKey);
6175 this.last = last; // reset the last
6176 view.focusRow(rowIndex);
6178 var isSelected = this.isSelected(rowIndex);
6179 if(e.ctrlKey && isSelected){
6180 this.deselectRow(rowIndex);
6181 }else if(!isSelected || this.getCount() > 1){
6182 this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
6183 view.focusRow(rowIndex);
6189 * Selects multiple rows.
6190 * @param {Array} rows Array of the indexes of the row to select
6191 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep
6192 * existing selections (defaults to <tt>false</tt>)
6194 selectRows : function(rows, keepExisting){
6196 this.clearSelections();
6198 for(var i = 0, len = rows.length; i < len; i++){
6199 this.selectRow(rows[i], true);
6204 * Selects a range of rows if the selection model
6205 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
6206 * All rows in between startRow and endRow are also selected.
6207 * @param {Number} startRow The index of the first row in the range
6208 * @param {Number} endRow The index of the last row in the range
6209 * @param {Boolean} keepExisting (optional) True to retain existing selections
6211 selectRange : function(startRow, endRow, keepExisting){
6213 if(this.isLocked()){
6217 this.clearSelections();
6219 if(startRow <= endRow){
6220 for(i = startRow; i <= endRow; i++){
6221 this.selectRow(i, true);
6224 for(i = startRow; i >= endRow; i--){
6225 this.selectRow(i, true);
6231 * Deselects a range of rows if the selection model
6232 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
6233 * All rows in between startRow and endRow are also deselected.
6234 * @param {Number} startRow The index of the first row in the range
6235 * @param {Number} endRow The index of the last row in the range
6237 deselectRange : function(startRow, endRow, preventViewNotify){
6238 if(this.isLocked()){
6241 for(var i = startRow; i <= endRow; i++){
6242 this.deselectRow(i, preventViewNotify);
6247 * Selects a row. Before selecting a row, checks if the selection model
6248 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked} and fires the
6249 * {@link #beforerowselect} event. If these checks are satisfied the row
6250 * will be selected and followed up by firing the {@link #rowselect} and
6251 * {@link #selectionchange} events.
6252 * @param {Number} row The index of the row to select
6253 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
6254 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
6255 * prevent notifying the view (disables updating the selected appearance)
6257 selectRow : function(index, keepExisting, preventViewNotify){
6258 if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){
6261 var r = this.grid.store.getAt(index);
6262 if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
6263 if(!keepExisting || this.singleSelect){
6264 this.clearSelections();
6266 this.selections.add(r);
6267 this.last = this.lastActive = index;
6268 if(!preventViewNotify){
6269 this.grid.getView().onRowSelect(index);
6272 this.fireEvent('rowselect', this, index, r);
6273 this.fireEvent('selectionchange', this);
6279 * Deselects a row. Before deselecting a row, checks if the selection model
6280 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked}.
6281 * If this check is satisfied the row will be deselected and followed up by
6282 * firing the {@link #rowdeselect} and {@link #selectionchange} events.
6283 * @param {Number} row The index of the row to deselect
6284 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
6285 * prevent notifying the view (disables updating the selected appearance)
6287 deselectRow : function(index, preventViewNotify){
6288 if(this.isLocked()){
6291 if(this.last == index){
6294 if(this.lastActive == index){
6295 this.lastActive = false;
6297 var r = this.grid.store.getAt(index);
6299 this.selections.remove(r);
6300 if(!preventViewNotify){
6301 this.grid.getView().onRowDeselect(index);
6303 this.fireEvent('rowdeselect', this, index, r);
6304 this.fireEvent('selectionchange', this);
6309 acceptsNav : function(row, col, cm){
6310 return !cm.isHidden(col) && cm.isCellEditable(col, row);
6314 onEditorKey : function(field, e){
6319 ed = g.activeEditor,
6327 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
6329 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
6331 }else if(k == e.ENTER){
6332 if(this.moveEditorOnEnter !== false){
6334 newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
6336 newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
6345 this.selectRow(r); // *** highlight newly-selected cell and update selection
6348 if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
6349 ae = g.activeEditor;
6350 if(ae && ae.field.triggerBlur){
6351 // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
6352 ae.field.triggerBlur();
6355 g.startEditing(r, c);
6359 destroy : function(){
6360 Ext.destroy(this.rowNav);
6362 Ext.grid.RowSelectionModel.superclass.destroy.call(this);
6365 * @class Ext.grid.Column
6366 * <p>This class encapsulates column configuration data to be used in the initialization of a
6367 * {@link Ext.grid.ColumnModel ColumnModel}.</p>
6368 * <p>While subclasses are provided to render data in different ways, this class renders a passed
6369 * data field unchanged and is usually used for textual columns.</p>
6371 Ext.grid.Column = Ext.extend(Ext.util.Observable, {
6373 * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured
6374 * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column.
6375 * The initial configuration may be dynamically altered using
6376 * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}.
6379 * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial
6380 * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all
6381 * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be
6382 * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre>
6383 * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre>
6384 * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre>
6385 * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this
6386 * unique identifier.
6389 * @cfg {String} header Optional. The header text to be used as innerHTML
6390 * (html tags are accepted) to display in the Grid view. <b>Note</b>: to
6391 * have a clickable header with no text displayed use <tt>'&#160;'</tt>.
6394 * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
6395 * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>,
6396 * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the
6397 * group option in the header menu for the column. See also <code>{@link #groupName}</code>.
6400 * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
6401 * may be used to specify the text with which to prefix the group field value in the group header line.
6402 * See also {@link #groupRenderer} and
6403 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}.
6406 * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
6407 * may be used to specify the function used to format the grouping field value for display in the group
6408 * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured
6409 * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified
6410 * the new value of the group field will be used.</p>
6411 * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be
6412 * passed the following parameters:
6413 * <div class="mdetail-params"><ul>
6414 * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li>
6415 * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li>
6416 * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data
6417 * for the row which caused group change.</p></li>
6418 * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>
6419 * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li>
6420 * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
6422 * <p>The function should return a string value.</p>
6425 * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
6426 * may be used to specify the text to display when there is an empty group value. Defaults to the
6427 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}.
6430 * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
6431 * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
6432 * which to draw the column's value.</p>
6435 * @cfg {Number} width
6436 * Optional. The initial width in pixels of the column.
6437 * The width of each column can also be affected if any of the following are configured:
6438 * <div class="mdetail-params"><ul>
6439 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li>
6440 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt>
6441 * <div class="sub-desc">
6442 * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be
6443 * re-proportioned (based on the relative initial widths) to fill the width of the grid so
6444 * that no horizontal scrollbar is shown.</p>
6446 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li>
6447 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li>
6448 * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side
6449 * is reserved for the vertical scrollbar. The
6450 * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt>
6451 * can be modified to reduce or eliminate the reserved offset.</p>
6454 * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column.
6455 * Defaults to the value of the <code>{@link Ext.grid.ColumnModel#defaultSortable}</code> property.
6456 * Whether local/remote sorting is used is specified in <code>{@link Ext.data.Store#remoteSort}</code>.
6459 * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>.
6462 * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>.
6465 * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>.
6468 * @cfg {Boolean} hidden
6469 * Optional. <tt>true</tt> to initially hide this column. Defaults to <tt>false</tt>.
6470 * A hidden column {@link Ext.grid.GridPanel#enableColumnHide may be shown via the header row menu}.
6471 * If a column is never to be shown, simply do not include this column in the Column Model at all.
6474 * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips
6475 * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the
6476 * header's HTML title attribute. Defaults to ''.
6479 * @cfg {Mixed} renderer
6480 * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p>
6481 * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value,
6482 * appearance, etc.) before it is rendered). This may be specified in either of three ways:
6483 * <div class="mdetail-params"><ul>
6484 * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li>
6485 * <li>A string which references a property name of the {@link Ext.util.Format} class which
6486 * provides a renderer function.</li>
6487 * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt>
6488 * reference) e.g.:<pre style="margin-left:1.2em"><code>
6490 fn: this.gridRenderer,
6493 </code></pre></li></ul></div>
6494 * If not specified, the default renderer uses the raw data value.</p>
6495 * <p>For information about the renderer function (passed parameters, etc.), see
6496 * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code>
6497 var companyColumn = {
6498 header: 'Company Name',
6499 dataIndex: 'company',
6500 renderer: function(value, metaData, record, rowIndex, colIndex, store) {
6501 // provide the logic depending on business rules
6502 // name of your own choosing to manipulate the cell depending upon
6503 // the data in the underlying Record object.
6504 if (value == 'whatever') {
6505 //metaData.css : String : A CSS class name to add to the TD element of the cell.
6506 //metaData.attr : String : An html attribute definition string to apply to
6507 // the data container element within the table
6508 // cell (e.g. 'style="color:red;"').
6509 metaData.css = 'name-of-css-class-you-will-define';
6515 * See also {@link #scope}.
6518 * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass
6519 * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily
6520 * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are:
6521 * <div class="mdetail-params"><ul>
6522 * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li>
6523 * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li>
6524 * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li>
6525 * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li>
6526 * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li>
6528 * <p>Configuration properties for the specified <code>xtype</code> may be specified with
6529 * the Column configuration properties, for example:</p>
6531 var grid = new Ext.grid.GridPanel({
6534 header: 'Last Updated',
6535 dataIndex: 'lastChange',
6538 //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
6539 xtype: 'datecolumn', // use xtype instead of renderer
6540 format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn}
6548 * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the
6549 * renderer. Defaults to the Column configuration object.
6552 * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined.
6555 * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column
6556 * (excluding headers). Defaults to undefined.
6559 * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column
6560 * (defaults to true). To disallow column hiding globally for all columns in the grid, use
6561 * {@link Ext.grid.GridPanel#enableColumnHide} instead.
6564 * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column
6565 * if editing is supported by the grid. See <tt>{@link #editable}</tt> also.
6570 * @cfg {Boolean} isColumn
6571 * Used by ColumnModel setConfig method to avoid reprocessing a Column
6572 * if <code>isColumn</code> is not set ColumnModel will recreate a new Ext.grid.Column
6577 constructor : function(config){
6578 Ext.apply(this, config);
6580 if(Ext.isString(this.renderer)){
6581 this.renderer = Ext.util.Format[this.renderer];
6582 }else if(Ext.isObject(this.renderer)){
6583 this.scope = this.renderer.scope;
6584 this.renderer = this.renderer.fn;
6590 var ed = this.editor;
6596 * Fires when this Column is clicked.
6597 * @param {Column} this
6598 * @param {Grid} The owning GridPanel
6599 * @param {Number} rowIndex
6600 * @param {Ext.EventObject} e
6604 * @event contextmenu
6605 * Fires when this Column is right clicked.
6606 * @param {Column} this
6607 * @param {Grid} The owning GridPanel
6608 * @param {Number} rowIndex
6609 * @param {Ext.EventObject} e
6614 * Fires when this Column is double clicked.
6615 * @param {Column} this
6616 * @param {Grid} The owning GridPanel
6617 * @param {Number} rowIndex
6618 * @param {Ext.EventObject} e
6623 * Fires when this Column receives a mousedown event.
6624 * @param {Column} this
6625 * @param {Grid} The owning GridPanel
6626 * @param {Number} rowIndex
6627 * @param {Ext.EventObject} e
6631 Ext.grid.Column.superclass.constructor.call(this);
6636 * Process and refire events routed from the GridView's processEvent method.
6637 * Returns the event handler's status to allow cancelling of GridView's bubbling process.
6639 processEvent : function(name, e, grid, rowIndex, colIndex){
6640 return this.fireEvent(name, this, grid, rowIndex, e);
6645 * Clean up. Remove any Editor. Remove any listeners.
6647 destroy: function() {
6649 this.setEditor(null);
6651 this.purgeListeners();
6655 * Optional. A function which returns displayable data when passed the following parameters:
6656 * <div class="mdetail-params"><ul>
6657 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
6658 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
6659 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
6660 * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container
6661 * element <i>within</i> the table cell (e.g. 'style="color:red;"').</p></li></ul></p></li>
6662 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was
6663 * extracted.</p></li>
6664 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
6665 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
6666 * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record
6667 * was extracted.</p></li>
6669 * @property renderer
6672 renderer : function(value){
6677 getEditor: function(rowIndex){
6678 return this.editable !== false ? this.editor : null;
6682 * Sets a new editor for this column.
6683 * @param {Ext.Editor/Ext.form.Field} editor The editor to set
6685 setEditor : function(editor){
6686 var ed = this.editor;
6689 ed.gridEditor.destroy();
6690 delete ed.gridEditor;
6697 //not an instance, create it
6698 if(!editor.isXType){
6699 editor = Ext.create(editor, 'textfield');
6701 this.editor = editor;
6706 * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}
6707 * used to edit the cell.
6708 * @param {Number} rowIndex The row index
6709 * @return {Ext.Editor}
6711 getCellEditor: function(rowIndex){
6712 var ed = this.getEditor(rowIndex);
6716 ed.gridEditor = new Ext.grid.GridEditor(ed);
6726 * @class Ext.grid.BooleanColumn
6727 * @extends Ext.grid.Column
6728 * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.Column#xtype xtype}
6729 * config option of {@link Ext.grid.Column} for more details.</p>
6731 Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {
6733 * @cfg {String} trueText
6734 * The string returned by the renderer when the column value is not falsy (defaults to <tt>'true'</tt>).
6738 * @cfg {String} falseText
6739 * The string returned by the renderer when the column value is falsy (but not undefined) (defaults to
6740 * <tt>'false'</tt>).
6744 * @cfg {String} undefinedText
6745 * The string returned by the renderer when the column value is undefined (defaults to <tt>'&#160;'</tt>).
6747 undefinedText: ' ',
6749 constructor: function(cfg){
6750 Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);
6751 var t = this.trueText, f = this.falseText, u = this.undefinedText;
6752 this.renderer = function(v){
6753 if(v === undefined){
6756 if(!v || v === 'false'){
6765 * @class Ext.grid.NumberColumn
6766 * @extends Ext.grid.Column
6767 * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the
6768 * {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more details.</p>
6770 Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {
6772 * @cfg {String} format
6773 * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
6774 * (defaults to <tt>'0,000.00'</tt>).
6776 format : '0,000.00',
6777 constructor: function(cfg){
6778 Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);
6779 this.renderer = Ext.util.Format.numberRenderer(this.format);
6784 * @class Ext.grid.DateColumn
6785 * @extends Ext.grid.Column
6786 * <p>A Column definition class which renders a passed date according to the default locale, or a configured
6787 * {@link #format}. See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column}
6788 * for more details.</p>
6790 Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {
6792 * @cfg {String} format
6793 * A formatting string as used by {@link Date#format} to format a Date for this Column
6794 * (defaults to <tt>'m/d/Y'</tt>).
6797 constructor: function(cfg){
6798 Ext.grid.DateColumn.superclass.constructor.call(this, cfg);
6799 this.renderer = Ext.util.Format.dateRenderer(this.format);
6804 * @class Ext.grid.TemplateColumn
6805 * @extends Ext.grid.Column
6806 * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s
6807 * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}.
6808 * See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more
6811 Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
6813 * @cfg {String/XTemplate} tpl
6814 * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a
6815 * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value.
6817 constructor: function(cfg){
6818 Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);
6819 var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl);
6820 this.renderer = function(value, p, r){
6821 return tpl.apply(r.data);
6828 * @class Ext.grid.ActionColumn
6829 * @extends Ext.grid.Column
6830 * <p>A Grid column type which renders an icon, or a series of icons in a grid cell, and offers a scoped click
6831 * handler for each icon. Example usage:</p>
6833 new Ext.grid.GridPanel({
6837 xtype: 'actioncolumn',
6841 icon : 'sell.gif', // Use a URL in the icon config
6842 tooltip: 'Sell stock',
6843 handler: function(grid, rowIndex, colIndex) {
6844 var rec = store.getAt(rowIndex);
6845 alert("Sell " + rec.get('company'));
6849 getClass: function(v, meta, rec) { // Or return a class from a function
6850 if (rec.get('change') < 0) {
6851 this.items[1].tooltip = 'Do not buy!';
6854 this.items[1].tooltip = 'Buy stock';
6858 handler: function(grid, rowIndex, colIndex) {
6859 var rec = store.getAt(rowIndex);
6860 alert("Buy " + rec.get('company'));
6865 //any other columns here
6869 * <p>The action column can be at any index in the columns array, and a grid can have any number of
6870 * action columns. </p>
6872 Ext.grid.ActionColumn = Ext.extend(Ext.grid.Column, {
6874 * @cfg {String} icon
6875 * The URL of an image to display as the clickable element in the column.
6876 * Optional - defaults to <code>{@link Ext#BLANK_IMAGE_URL Ext.BLANK_IMAGE_URL}</code>.
6879 * @cfg {String} iconCls
6880 * A CSS class to apply to the icon image. To determine the class dynamically, configure the Column with a <code>{@link #getClass}</code> function.
6883 * @cfg {Function} handler A function called when the icon is clicked.
6884 * The handler is passed the following parameters:<div class="mdetail-params"><ul>
6885 * <li><code>grid</code> : GridPanel<div class="sub-desc">The owning GridPanel.</div></li>
6886 * <li><code>rowIndex</code> : Number<div class="sub-desc">The row index clicked on.</div></li>
6887 * <li><code>colIndex</code> : Number<div class="sub-desc">The column index clicked on.</div></li>
6888 * <li><code>item</code> : Object<div class="sub-desc">The clicked item (or this Column if multiple
6889 * {@link #items} were not configured).</div></li>
6890 * <li><code>e</code> : Event<div class="sub-desc">The click event.</div></li>
6894 * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
6895 * and <code>{@link #getClass}</code> fuctions are executed. Defaults to this Column.
6898 * @cfg {String} tooltip A tooltip message to be displayed on hover. {@link Ext.QuickTips#init Ext.QuickTips} must have
6902 * @cfg {Boolean} stopSelection Defaults to <code>true</code>. Prevent grid <i>row</i> selection upon mousedown.
6905 * @cfg {Function} getClass A function which returns the CSS class to apply to the icon image.
6906 * The function is passed the following parameters:<ul>
6907 * <li><b>v</b> : Object<p class="sub-desc">The value of the column's configured field (if any).</p></li>
6908 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
6909 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
6910 * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell
6911 * (e.g. 'style="color:red;"').</p></li>
6913 * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data.</p></li>
6914 * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index..</p></li>
6915 * <li><b>colIndex</b> : Number<p class="sub-desc">The column index.</p></li>
6916 * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
6920 * @cfg {Array} items An Array which may contain multiple icon definitions, each element of which may contain:
6921 * <div class="mdetail-params"><ul>
6922 * <li><code>icon</code> : String<div class="sub-desc">The url of an image to display as the clickable element
6923 * in the column.</div></li>
6924 * <li><code>iconCls</code> : String<div class="sub-desc">A CSS class to apply to the icon image.
6925 * To determine the class dynamically, configure the item with a <code>getClass</code> function.</div></li>
6926 * <li><code>getClass</code> : Function<div class="sub-desc">A function which returns the CSS class to apply to the icon image.
6927 * The function is passed the following parameters:<ul>
6928 * <li><b>v</b> : Object<p class="sub-desc">The value of the column's configured field (if any).</p></li>
6929 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
6930 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
6931 * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell
6932 * (e.g. 'style="color:red;"').</p></li>
6934 * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data.</p></li>
6935 * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index..</p></li>
6936 * <li><b>colIndex</b> : Number<p class="sub-desc">The column index.</p></li>
6937 * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
6939 * <li><code>handler</code> : Function<div class="sub-desc">A function called when the icon is clicked.</div></li>
6940 * <li><code>scope</code> : Scope<div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the
6941 * <code>handler</code> and <code>getClass</code> functions are executed. Fallback defaults are this Column's
6942 * configured scope, then this Column.</div></li>
6943 * <li><code>tooltip</code> : String<div class="sub-desc">A tooltip message to be displayed on hover.
6944 * {@link Ext.QuickTips#init Ext.QuickTips} must have been initialized.</div></li>
6949 actionIdRe: /x-action-col-(\d+)/,
6952 * @cfg {String} altText The alt text to use for the image element. Defaults to <tt>''</tt>.
6956 constructor: function(cfg) {
6958 items = cfg.items || (me.items = [me]),
6963 Ext.grid.ActionColumn.superclass.constructor.call(me, cfg);
6965 // Renderer closure iterates through items creating an <img> element for each and tagging with an identifying
6966 // class name x-action-col-{n}
6967 me.renderer = function(v, meta) {
6968 // Allow a configured renderer to create initial value (And set the other values in the "metadata" argument!)
6969 v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : '';
6971 meta.css += ' x-action-col-cell';
6972 for (i = 0; i < l; i++) {
6974 v += '<img alt="' + me.altText + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
6975 '" class="x-action-col-icon x-action-col-' + String(i) + ' ' + (item.iconCls || '') +
6976 ' ' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||this.scope||this, arguments) : '') + '"' +
6977 ((item.tooltip) ? ' ext:qtip="' + item.tooltip + '"' : '') + ' />';
6983 destroy: function() {
6985 delete this.renderer;
6986 return Ext.grid.ActionColumn.superclass.destroy.apply(this, arguments);
6991 * Process and refire events routed from the GridView's processEvent method.
6992 * Also fires any configured click handlers. By default, cancels the mousedown event to prevent selection.
6993 * Returns the event handler's status to allow cancelling of GridView's bubbling process.
6995 processEvent : function(name, e, grid, rowIndex, colIndex){
6996 var m = e.getTarget().className.match(this.actionIdRe),
6998 if (m && (item = this.items[parseInt(m[1], 10)])) {
6999 if (name == 'click') {
7000 (fn = item.handler || this.handler) && fn.call(item.scope||this.scope||this, grid, rowIndex, colIndex, item, e);
7001 } else if ((name == 'mousedown') && (item.stopSelection !== false)) {
7005 return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
7012 * @member Ext.grid.Column
7014 * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced
7015 * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p>
7016 * <p>This contains the following properties</p><div class="mdesc-details"><ul>
7017 * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li>
7018 * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li>
7019 * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li>
7020 * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li>
7021 * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li>
7024 Ext.grid.Column.types = {
7025 gridcolumn : Ext.grid.Column,
7026 booleancolumn: Ext.grid.BooleanColumn,
7027 numbercolumn: Ext.grid.NumberColumn,
7028 datecolumn: Ext.grid.DateColumn,
7029 templatecolumn: Ext.grid.TemplateColumn,
7030 actioncolumn: Ext.grid.ActionColumn
7032 * @class Ext.grid.RowNumberer
7033 * This is a utility class that can be passed into a {@link Ext.grid.ColumnModel} as a column config that provides
7034 * an automatic row numbering column.
7037 // This is a typical column config with the first column providing row numbers
7038 var colModel = new Ext.grid.ColumnModel([
7039 new Ext.grid.RowNumberer(),
7040 {header: "Name", width: 80, sortable: true},
7041 {header: "Code", width: 50, sortable: true},
7042 {header: "Description", width: 200, sortable: true}
7046 * @param {Object} config The configuration options
7048 Ext.grid.RowNumberer = Ext.extend(Object, {
7050 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
7051 * number column (defaults to '').
7055 * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
7059 * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
7064 constructor : function(config){
7065 Ext.apply(this, config);
7067 this.renderer = this.renderer.createDelegate(this);
7080 renderer : function(v, p, record, rowIndex){
7082 p.cellAttr = 'rowspan="'+this.rowspan+'"';
7087 * @class Ext.grid.CheckboxSelectionModel
7088 * @extends Ext.grid.RowSelectionModel
7089 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
7091 * @param {Object} config The configuration options
7093 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
7096 * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
7097 * checkbox column (defaults to <tt>false</tt>).
7100 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
7101 * checkbox column. Defaults to:<pre><code>
7102 * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
7104 * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
7105 * and provides support for automatic check all/none behavior on header click. This string
7106 * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
7107 * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
7108 * <tt>'x-grid3-hd-checker'</tt> class is supplied.
7110 header : '<div class="x-grid3-hd-checker"> </div>',
7112 * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
7116 * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
7122 menuDisabled : true,
7127 isColumn: true, // So that ColumnModel doesn't feed this through the Column constructor
7129 constructor : function(){
7130 Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
7132 this.handleMouseDown = Ext.emptyFn;
7137 initEvents : function(){
7138 Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
7139 this.grid.on('render', function(){
7140 Ext.fly(this.grid.getView().innerHd).on('mousedown', this.onHdMouseDown, this);
7146 * Process and refire events routed from the GridView's processEvent method.
7148 processEvent : function(name, e, grid, rowIndex, colIndex){
7149 if (name == 'mousedown') {
7150 this.onMouseDown(e, e.getTarget());
7153 return Ext.grid.Column.prototype.processEvent.apply(this, arguments);
7158 onMouseDown : function(e, t){
7159 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
7161 var row = e.getTarget('.x-grid3-row');
7163 var index = row.rowIndex;
7164 if(this.isSelected(index)){
7165 this.deselectRow(index);
7167 this.selectRow(index, true);
7168 this.grid.getView().focusRow(index);
7175 onHdMouseDown : function(e, t) {
7176 if(t.className == 'x-grid3-hd-checker'){
7178 var hd = Ext.fly(t.parentNode);
7179 var isChecked = hd.hasClass('x-grid3-hd-checker-on');
7181 hd.removeClass('x-grid3-hd-checker-on');
7182 this.clearSelections();
7184 hd.addClass('x-grid3-hd-checker-on');
7191 renderer : function(v, p, record){
7192 return '<div class="x-grid3-row-checker"> </div>';