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,
101 * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
102 * can have (if enabled). Defaults to <tt>1000</tt>.
104 autoExpandMax : 1000,
106 * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
107 * can have (if enabled). Defaults to <tt>50</tt>.
111 * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
112 * Default is <tt>false</tt>.
116 * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
119 * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
122 * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
123 * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
124 * <tt>{@link #colModel}</tt> configuration property.
127 * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.
130 * @cfg {String} ddText
131 * Configures the text in the drag proxy. Defaults to:
133 * ddText : '{0} selected row{1}'
135 * <tt>{0}</tt> is replaced with the number of selected rows.
137 ddText : '{0} selected row{1}',
139 * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>
140 * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row
141 * structure deferred so that layouts with GridPanels appear more quickly.</p>
143 deferRowRender : true,
145 * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>
146 * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>
149 * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
152 * @cfg {Boolean} enableColumnHide
153 * Defaults to <tt>true</tt> to enable {@link Ext.grid.Column#hidden hiding of columns}
154 * with the {@link #enableHdMenu header menu}.
156 enableColumnHide : true,
158 * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>
159 * to turn off column reordering via drag drop.
161 enableColumnMove : true,
163 * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>
164 * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to
165 * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>
166 * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>
168 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of
169 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
170 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able
171 * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>
173 enableDragDrop : false,
175 * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
179 * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
182 * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
183 * loading. Defaults to <code>false</code>.
187 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
190 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
194 * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
197 * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide
198 * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).
201 * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
204 * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.
205 * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of
206 * the grid. A default CSS rule is provided which sets a background colour, but you can override this
207 * with a rule which either overrides the <b>background-color</b> style using the '!important'
208 * modifier, or which uses a CSS selector of higher specificity.</p>
212 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>
213 * for GridPanel, but <tt>false</tt> for EditorGridPanel.
215 trackMouseOver : true,
217 * @cfg {Array} stateEvents
218 * An array of events that, when fired, should trigger this component to save its state.
219 * Defaults to:<pre><code>
220 * stateEvents: ['columnmove', 'columnresize', 'sortchange', 'groupchange']
222 * <p>These can be any types of events supported by this component, including browser or
223 * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>
224 * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring
225 * Component state.</p>
227 stateEvents : ['columnmove', 'columnresize', 'sortchange', 'groupchange'],
229 * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set
230 * before a call to {@link Ext.Component#render render()}.
235 * @cfg {Array} bubbleEvents
236 * <p>An array of events that, when fired, should be bubbled to any parent container.
237 * See {@link Ext.util.Observable#enableBubble}.
238 * Defaults to <tt>[]</tt>.
243 * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of
244 * the config options available for {@link Ext.grid.GridView} can be specified here. This option
245 * is ignored if <tt>{@link #view}</tt> is specified.
254 initComponent : function(){
255 Ext.grid.GridPanel.superclass.initComponent.call(this);
257 if(this.columnLines){
258 this.cls = (this.cls || '') + ' x-grid-with-col-lines';
260 // override any provided value since it isn't valid
261 // and is causing too many bug reports ;)
262 this.autoScroll = false;
263 this.autoWidth = false;
265 if(Ext.isArray(this.columns)){
266 this.colModel = new Ext.grid.ColumnModel(this.columns);
270 // check and correct shorthanded configs
272 this.store = this.ds;
276 this.colModel = this.cm;
280 this.selModel = this.sm;
283 this.store = Ext.StoreMgr.lookup(this.store);
289 * The raw click event for the entire grid.
290 * @param {Ext.EventObject} e
295 * The raw dblclick event for the entire grid.
296 * @param {Ext.EventObject} e
301 * The raw contextmenu event for the entire grid.
302 * @param {Ext.EventObject} e
307 * The raw mousedown event for the entire grid.
308 * @param {Ext.EventObject} e
313 * The raw mouseup event for the entire grid.
314 * @param {Ext.EventObject} e
319 * The raw mouseover event for the entire grid.
320 * @param {Ext.EventObject} e
325 * The raw mouseout event for the entire grid.
326 * @param {Ext.EventObject} e
331 * The raw keypress event for the entire grid.
332 * @param {Ext.EventObject} e
337 * The raw keydown event for the entire grid.
338 * @param {Ext.EventObject} e
344 * @event cellmousedown
345 * Fires before a cell is clicked
347 * @param {Number} rowIndex
348 * @param {Number} columnIndex
349 * @param {Ext.EventObject} e
353 * @event rowmousedown
354 * Fires before a row is clicked
356 * @param {Number} rowIndex
357 * @param {Ext.EventObject} e
361 * @event headermousedown
362 * Fires before a header is clicked
364 * @param {Number} columnIndex
365 * @param {Ext.EventObject} e
370 * @event groupmousedown
371 * Fires before a group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
373 * @param {String} groupField
374 * @param {String} groupValue
375 * @param {Ext.EventObject} e
380 * @event rowbodymousedown
381 * Fires before the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
383 * @param {Number} rowIndex
384 * @param {Ext.EventObject} e
389 * @event containermousedown
390 * Fires before the container is clicked. The container consists of any part of the grid body that is not covered by a row.
392 * @param {Ext.EventObject} e
394 'containermousedown',
398 * Fires when a cell is clicked.
399 * The data for the cell is drawn from the {@link Ext.data.Record Record}
400 * for this row. To access the data in the listener function use the
401 * following technique:
403 function(grid, rowIndex, columnIndex, e) {
404 var record = grid.getStore().getAt(rowIndex); // Get the Record
405 var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
406 var data = record.get(fieldName);
410 * @param {Number} rowIndex
411 * @param {Number} columnIndex
412 * @param {Ext.EventObject} e
416 * @event celldblclick
417 * Fires when a cell is double clicked
419 * @param {Number} rowIndex
420 * @param {Number} columnIndex
421 * @param {Ext.EventObject} e
426 * Fires when a row is clicked
428 * @param {Number} rowIndex
429 * @param {Ext.EventObject} e
434 * Fires when a row is double clicked
436 * @param {Number} rowIndex
437 * @param {Ext.EventObject} e
442 * Fires when a header is clicked
444 * @param {Number} columnIndex
445 * @param {Ext.EventObject} e
449 * @event headerdblclick
450 * Fires when a header cell is double clicked
452 * @param {Number} columnIndex
453 * @param {Ext.EventObject} e
458 * Fires when group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
460 * @param {String} groupField
461 * @param {String} groupValue
462 * @param {Ext.EventObject} e
466 * @event groupdblclick
467 * Fires when group header is double clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
469 * @param {String} groupField
470 * @param {String} groupValue
471 * @param {Ext.EventObject} e
475 * @event containerclick
476 * Fires when the container is clicked. The container consists of any part of the grid body that is not covered by a row.
478 * @param {Ext.EventObject} e
482 * @event containerdblclick
483 * Fires when the container is double clicked. The container consists of any part of the grid body that is not covered by a row.
485 * @param {Ext.EventObject} e
490 * @event rowbodyclick
491 * Fires when the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
493 * @param {Number} rowIndex
494 * @param {Ext.EventObject} e
498 * @event rowbodydblclick
499 * Fires when the row body is double clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
501 * @param {Number} rowIndex
502 * @param {Ext.EventObject} e
507 * @event rowcontextmenu
508 * Fires when a row is right clicked
510 * @param {Number} rowIndex
511 * @param {Ext.EventObject} e
515 * @event cellcontextmenu
516 * Fires when a cell is right clicked
518 * @param {Number} rowIndex
519 * @param {Number} cellIndex
520 * @param {Ext.EventObject} e
524 * @event headercontextmenu
525 * Fires when a header is right clicked
527 * @param {Number} columnIndex
528 * @param {Ext.EventObject} e
532 * @event groupcontextmenu
533 * Fires when group header is right clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
535 * @param {String} groupField
536 * @param {String} groupValue
537 * @param {Ext.EventObject} e
541 * @event containercontextmenu
542 * Fires when the container is right clicked. The container consists of any part of the grid body that is not covered by a row.
544 * @param {Ext.EventObject} e
546 'containercontextmenu',
548 * @event rowbodycontextmenu
549 * Fires when the row body is right clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
551 * @param {Number} rowIndex
552 * @param {Ext.EventObject} e
554 'rowbodycontextmenu',
557 * Fires when the body element is scrolled
558 * @param {Number} scrollLeft
559 * @param {Number} scrollTop
563 * @event columnresize
564 * Fires when the user resizes a column
565 * @param {Number} columnIndex
566 * @param {Number} newSize
571 * Fires when the user moves a column
572 * @param {Number} oldIndex
573 * @param {Number} newIndex
578 * Fires when the grid's store sort changes
580 * @param {Object} sortInfo An object with the keys field and direction
585 * Fires when the grid's grouping changes (only applies for grids with a {@link Ext.grid.GroupingView GroupingView})
587 * @param {String} groupField A string with the grouping field, null if the store is not grouped.
592 * Fires when the grid is reconfigured with a new store and/or column model.
594 * @param {Ext.data.Store} store The new store
595 * @param {Ext.grid.ColumnModel} colModel The new column model
600 * Fires when the grid view is available (use this for selecting a default row).
608 onRender : function(ct, position){
609 Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
611 var c = this.getGridEl();
613 this.el.addClass('x-grid-panel');
617 mousedown: this.onMouseDown,
619 dblclick: this.onDblClick,
620 contextmenu: this.onContextMenu
623 this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress', 'keydown']);
625 var view = this.getView();
628 this.getSelectionModel().init(this);
632 initEvents : function(){
633 Ext.grid.GridPanel.superclass.initEvents.call(this);
636 this.loadMask = new Ext.LoadMask(this.bwrap,
637 Ext.apply({store:this.store}, this.loadMask));
641 initStateEvents : function(){
642 Ext.grid.GridPanel.superclass.initStateEvents.call(this);
643 this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
646 applyState : function(state){
647 var cm = this.colModel,
655 for(var i = 0, len = cs.length; i < len; i++){
657 c = cm.getColumnById(s.id);
661 oldIndex = cm.getIndexById(s.id);
663 cm.moveColumn(oldIndex, i);
671 store[store.remoteSort ? 'setDefaultSort' : 'sort'](s.field, s.direction);
678 store.clearGrouping();
683 var o = Ext.apply({}, state);
686 Ext.grid.GridPanel.superclass.applyState.call(this, o);
689 getState : function(){
690 var o = {columns: []},
695 for(var i = 0, c; (c = this.colModel.config[i]); i++){
701 o.columns[i].hidden = true;
705 ss = store.getSortState();
709 if(store.getGroupState){
710 gs = store.getGroupState();
720 afterRender : function(){
721 Ext.grid.GridPanel.superclass.afterRender.call(this);
723 this.on('bodyresize', v.layout, v);
725 if(this.deferRowRender){
726 if (!this.deferRowRenderTask){
727 this.deferRowRenderTask = new Ext.util.DelayedTask(v.afterRender, this.view);
729 this.deferRowRenderTask.delay(10);
733 this.viewReady = true;
737 * <p>Reconfigures the grid to use a different Store and Column Model
738 * and fires the 'reconfigure' event. The View will be bound to the new
739 * objects and refreshed.</p>
740 * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
741 * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
742 * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
743 * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
744 * with the new data.</p>
745 * @param {Ext.data.Store} store The new {@link Ext.data.Store} object
746 * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
748 reconfigure : function(store, colModel){
749 var rendered = this.rendered;
752 this.loadMask.destroy();
753 this.loadMask = new Ext.LoadMask(this.bwrap,
754 Ext.apply({}, {store:store}, this.initialConfig.loadMask));
758 this.view.initData(store, colModel);
761 this.colModel = colModel;
763 this.view.refresh(true);
765 this.fireEvent('reconfigure', this, store, colModel);
769 onDestroy : function(){
770 if (this.deferRowRenderTask && this.deferRowRenderTask.cancel){
771 this.deferRowRenderTask.cancel();
774 Ext.destroy(this.view, this.loadMask);
775 }else if(this.store && this.store.autoDestroy){
776 this.store.destroy();
778 Ext.destroy(this.colModel, this.selModel);
779 this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
780 Ext.grid.GridPanel.superclass.onDestroy.call(this);
784 processEvent : function(name, e){
785 this.view.processEvent(name, e);
789 onClick : function(e){
790 this.processEvent('click', e);
794 onMouseDown : function(e){
795 this.processEvent('mousedown', e);
799 onContextMenu : function(e, t){
800 this.processEvent('contextmenu', e);
804 onDblClick : function(e){
805 this.processEvent('dblclick', e);
809 walkCells : function(row, col, step, fn, scope){
810 var cm = this.colModel,
811 clen = cm.getColumnCount(),
813 rlen = ds.getCount(),
827 if(fn.call(scope || this, row, col, cm) === true){
845 if(fn.call(scope || this, row, col, cm) === true){
857 * Returns the grid's underlying element.
858 * @return {Element} The element
860 getGridEl : function(){
864 // private for compatibility, overridden by editor grid
865 stopEditing : Ext.emptyFn,
868 * Returns the grid's selection model configured by the <code>{@link #selModel}</code>
869 * configuration option. If no selection model was configured, this will create
870 * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
871 * @return {SelectionModel}
873 getSelectionModel : function(){
875 this.selModel = new Ext.grid.RowSelectionModel(
876 this.disableSelection ? {selectRow: Ext.emptyFn} : null);
878 return this.selModel;
882 * Returns the grid's data store.
883 * @return {Ext.data.Store} The store
885 getStore : function(){
890 * Returns the grid's ColumnModel.
891 * @return {Ext.grid.ColumnModel} The column model
893 getColumnModel : function(){
894 return this.colModel;
898 * Returns the grid's GridView object.
899 * @return {Ext.grid.GridView} The grid view
901 getView : function(){
903 this.view = new Ext.grid.GridView(this.viewConfig);
908 * Called to get grid's drag proxy text, by default returns this.ddText.
909 * @return {String} The text
911 getDragDropText : function(){
912 var count = this.selModel.getCount();
913 return String.format(this.ddText, count, count == 1 ? '' : 's');
917 * @cfg {String/Number} activeItem
921 * @cfg {Boolean} autoDestroy
925 * @cfg {Object/String/Function} autoLoad
929 * @cfg {Boolean} autoWidth
933 * @cfg {Boolean/Number} bufferResize
937 * @cfg {String} defaultType
941 * @cfg {Object} defaults
945 * @cfg {Boolean} hideBorders
953 * @cfg {String} layout
957 * @cfg {Object} layoutConfig
961 * @cfg {Boolean} monitorResize
997 * @method getComponent
1005 * @method getUpdater
1025 * @event afterlayout
1033 * @event beforeremove
1044 * @cfg {String} allowDomMove @hide
1047 * @cfg {String} autoEl @hide
1050 * @cfg {String} applyTo @hide
1053 * @cfg {String} autoScroll @hide
1056 * @cfg {String} bodyBorder @hide
1059 * @cfg {String} bodyStyle @hide
1062 * @cfg {String} contentEl @hide
1065 * @cfg {String} disabledClass @hide
1068 * @cfg {String} elements @hide
1071 * @cfg {String} html @hide
1074 * @cfg {Boolean} preventBodyReset
1078 * @property disabled
1082 * @method applyToMarkup
1094 * @method setDisabled
1098 Ext.reg('grid', Ext.grid.GridPanel);/**
1099 * @class Ext.grid.GridView
1100 * @extends Ext.util.Observable
1101 * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
1102 * Methods of this class may be used to access user interface elements to enable
1103 * special display effects. Do not change the DOM structure of the user interface.</p>
1104 * <p>This class does not provide ways to manipulate the underlying data. The data
1105 * model of a Grid is held in an {@link Ext.data.Store}.</p>
1107 * @param {Object} config
1109 Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
1111 * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
1112 * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
1113 * parameter. This function should return the CSS class name (or empty string '' for none) that will be added
1114 * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
1115 * (e.g., 'my-class another-class'). Example usage:
1119 showPreview: true, // custom property
1120 enableRowBody: true, // required to create a second, full-width row to show expanded Record data
1121 getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
1122 if(this.showPreview){
1123 rp.body = '<p>'+record.data.excerpt+'</p>';
1124 return 'x-grid3-row-expanded';
1126 return 'x-grid3-row-collapsed';
1130 * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
1131 * @param {Number} index The row index.
1132 * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
1133 * customization of various aspects of a grid row.
1134 * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
1135 * by this function, and will be used to render a full-width expansion row below each grid row:</p>
1137 * <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>
1138 * <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>
1140 * The following property will be passed in, and may be appended to:
1142 * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates
1143 * both the standard grid row, and any expansion row.</div></li>
1145 * @param {Store} store The {@link Ext.data.Store} this grid is bound to
1146 * @method getRowClass
1147 * @return {String} a CSS class name to add to the row.
1151 * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
1152 * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
1156 * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
1157 * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
1159 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1164 * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
1165 * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
1166 * config to disable the <i>menu</i> for individual columns. While this config is true the
1167 * following will be disabled:<div class="mdetail-params"><ul>
1168 * <li>clicking on header to sort</li>
1169 * <li>the trigger to reveal the menu.</li>
1174 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
1175 * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
1176 * See {@link Ext.grid.GridDragZone} for details.</p>
1177 * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>
1178 * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>
1179 * <li><i>after</i> the owning GridPanel has been rendered.</li>
1181 * @property dragZone
1182 * @type {Ext.grid.GridDragZone}
1186 * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
1187 * first load (defaults to <tt>true</tt>).
1189 deferEmptyText : true,
1192 * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
1193 * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
1196 scrollOffset : undefined,
1199 * @cfg {Boolean} autoFill
1200 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1201 * when the grid is <b>initially rendered</b>. The
1202 * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
1203 * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
1204 * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
1205 * See <tt>{@link #forceFit}</tt> also.
1210 * @cfg {Boolean} forceFit
1211 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1212 * at <b>all times</b>. The {@link Ext.grid.Column#width initially configured width}</tt> of each
1213 * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are
1214 * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized
1215 * to fit the grid width. See <tt>{@link #autoFill}</tt> also.
1220 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
1222 sortClasses : ['sort-asc', 'sort-desc'],
1225 * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
1227 sortAscText : 'Sort Ascending',
1230 * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
1232 sortDescText : 'Sort Descending',
1235 * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>)
1237 columnsText : 'Columns',
1240 * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An
1241 * example overriding the default styling:
1243 .x-grid3-row-selected {background-color: yellow;}
1245 * Note that this only controls the row, and will not do anything for the text inside it. To style inner
1246 * facets (like text) use something like:
1248 .x-grid3-row-selected .x-grid3-cell-inner {
1254 selectedRowClass : 'x-grid3-row-selected',
1258 tdClass : 'x-grid3-cell',
1259 hdCls : 'x-grid3-hd',
1263 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
1265 cellSelectorDepth : 4,
1267 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
1269 rowSelectorDepth : 10,
1272 * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
1274 rowBodySelectorDepth : 10,
1277 * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
1279 cellSelector : 'td.x-grid3-cell',
1281 * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
1283 rowSelector : 'div.x-grid3-row',
1286 * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
1288 rowBodySelector : 'div.x-grid3-row-body',
1291 firstRowCls: 'x-grid3-row-first',
1292 lastRowCls: 'x-grid3-row-last',
1293 rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
1295 constructor : function(config){
1296 Ext.apply(this, config);
1297 // These events are only used internally by the grid components
1300 * @event beforerowremoved
1301 * Internal UI Event. Fired before a row is removed.
1302 * @param {Ext.grid.GridView} view
1303 * @param {Number} rowIndex The index of the row to be removed.
1304 * @param {Ext.data.Record} record The Record to be removed
1308 * @event beforerowsinserted
1309 * Internal UI Event. Fired before rows are inserted.
1310 * @param {Ext.grid.GridView} view
1311 * @param {Number} firstRow The index of the first row to be inserted.
1312 * @param {Number} lastRow The index of the last row to be inserted.
1314 'beforerowsinserted',
1316 * @event beforerefresh
1317 * Internal UI Event. Fired before the view is refreshed.
1318 * @param {Ext.grid.GridView} view
1323 * Internal UI Event. Fired after a row is removed.
1324 * @param {Ext.grid.GridView} view
1325 * @param {Number} rowIndex The index of the row that was removed.
1326 * @param {Ext.data.Record} record The Record that was removed
1330 * @event rowsinserted
1331 * Internal UI Event. Fired after rows are inserted.
1332 * @param {Ext.grid.GridView} view
1333 * @param {Number} firstRow The index of the first inserted.
1334 * @param {Number} lastRow The index of the last row inserted.
1339 * Internal UI Event. Fired after a row has been updated.
1340 * @param {Ext.grid.GridView} view
1341 * @param {Number} firstRow The index of the row updated.
1342 * @param {Ext.data.record} record The Record backing the row updated.
1347 * Internal UI Event. Fired after the GridView's body has been refreshed.
1348 * @param {Ext.grid.GridView} view
1352 Ext.grid.GridView.superclass.constructor.call(this);
1355 /* -------------------------------- UI Specific ----------------------------- */
1358 initTemplates : function(){
1359 var ts = this.templates || {};
1361 ts.master = new Ext.Template(
1362 '<div class="x-grid3" hidefocus="true">',
1363 '<div class="x-grid3-viewport">',
1364 '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
1365 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
1367 '<div class="x-grid3-resize-marker"> </div>',
1368 '<div class="x-grid3-resize-proxy"> </div>',
1374 ts.header = new Ext.Template(
1375 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1376 '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
1382 ts.hcell = new Ext.Template(
1383 '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
1384 '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
1390 ts.body = new Ext.Template('{rows}');
1394 ts.row = new Ext.Template(
1395 '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1396 '<tbody><tr>{cells}</tr>',
1397 (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
1398 '</tbody></table></div>'
1403 ts.cell = new Ext.Template(
1404 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
1405 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
1412 if(t && Ext.isFunction(t.compile) && !t.compiled){
1413 t.disableFormats = true;
1418 this.templates = ts;
1419 this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
1424 if(!this._flyweight){
1425 this._flyweight = new Ext.Element.Flyweight(document.body);
1427 this._flyweight.dom = el;
1428 return this._flyweight;
1432 getEditorParent : function(){
1433 return this.scroller.dom;
1437 initElements : function(){
1438 var E = Ext.Element;
1440 var el = this.grid.getGridEl().dom.firstChild;
1441 var cs = el.childNodes;
1443 this.el = new E(el);
1445 this.mainWrap = new E(cs[0]);
1446 this.mainHd = new E(this.mainWrap.dom.firstChild);
1448 if(this.grid.hideHeaders){
1449 this.mainHd.setDisplayed(false);
1452 this.innerHd = this.mainHd.dom.firstChild;
1453 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
1455 this.scroller.setStyle('overflow-x', 'hidden');
1458 * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
1459 * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
1461 * @property mainBody
1463 this.mainBody = new E(this.scroller.dom.firstChild);
1465 this.focusEl = new E(this.scroller.dom.childNodes[1]);
1466 this.focusEl.swallowEvent('click', true);
1468 this.resizeMarker = new E(cs[1]);
1469 this.resizeProxy = new E(cs[2]);
1473 getRows : function(){
1474 return this.hasRows() ? this.mainBody.dom.childNodes : [];
1477 // finder methods, used with delegation
1480 findCell : function(el){
1484 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
1488 * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
1489 * See also {@link #findRowIndex}
1490 * @param {HTMLElement} el The target element
1491 * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
1493 findCellIndex : function(el, requiredCls){
1494 var cell = this.findCell(el);
1495 if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
1496 return this.getCellIndex(cell);
1502 getCellIndex : function(el){
1504 var m = el.className.match(this.colRe);
1506 return this.cm.getIndexById(m[1]);
1513 findHeaderCell : function(el){
1514 var cell = this.findCell(el);
1515 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
1519 findHeaderIndex : function(el){
1520 return this.findCellIndex(el, this.hdCls);
1524 * Return the HtmlElement representing the grid row which contains the passed element.
1525 * @param {HTMLElement} el The target HTMLElement
1526 * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
1528 findRow : function(el){
1532 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
1536 * <p>Return the index of the grid row which contains the passed HTMLElement.</p>
1537 * See also {@link #findCellIndex}
1538 * @param {HTMLElement} el The target HTMLElement
1539 * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
1541 findRowIndex : function(el){
1542 var r = this.findRow(el);
1543 return r ? r.rowIndex : false;
1547 * Return the HtmlElement representing the grid row body which contains the passed element.
1548 * @param {HTMLElement} el The target HTMLElement
1549 * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
1551 findRowBody : function(el){
1555 return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
1558 // getter methods for fetching elements dynamically in the grid
1561 * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
1562 * @param {Number} index The row index
1563 * @return {HtmlElement} The div element.
1565 getRow : function(row){
1566 return this.getRows()[row];
1570 * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
1571 * @param {Number} row The row index in which to find the cell.
1572 * @param {Number} col The column index of the cell.
1573 * @return {HtmlElement} The td at the specified coordinates.
1575 getCell : function(row, col){
1576 return this.getRow(row).getElementsByTagName('td')[col];
1580 * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
1581 * @param {Number} index The column index
1582 * @return {HtmlElement} The td element.
1584 getHeaderCell : function(index){
1585 return this.mainHd.dom.getElementsByTagName('td')[index];
1588 // manipulating elements
1590 // private - use getRowClass to apply custom row classes
1591 addRowClass : function(row, cls){
1592 var r = this.getRow(row);
1594 this.fly(r).addClass(cls);
1599 removeRowClass : function(row, cls){
1600 var r = this.getRow(row);
1602 this.fly(r).removeClass(cls);
1607 removeRow : function(row){
1608 Ext.removeNode(this.getRow(row));
1609 this.syncFocusEl(row);
1613 removeRows : function(firstRow, lastRow){
1614 var bd = this.mainBody.dom;
1615 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
1616 Ext.removeNode(bd.childNodes[firstRow]);
1618 this.syncFocusEl(firstRow);
1624 getScrollState : function(){
1625 var sb = this.scroller.dom;
1626 return {left: sb.scrollLeft, top: sb.scrollTop};
1630 restoreScroll : function(state){
1631 var sb = this.scroller.dom;
1632 sb.scrollLeft = state.left;
1633 sb.scrollTop = state.top;
1637 * Scrolls the grid to the top
1639 scrollToTop : function(){
1640 this.scroller.dom.scrollTop = 0;
1641 this.scroller.dom.scrollLeft = 0;
1645 syncScroll : function(){
1646 this.syncHeaderScroll();
1647 var mb = this.scroller.dom;
1648 this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
1652 syncHeaderScroll : function(){
1653 var mb = this.scroller.dom;
1654 this.innerHd.scrollLeft = mb.scrollLeft;
1655 this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
1659 updateSortIcon : function(col, dir){
1660 var sc = this.sortClasses;
1661 var hds = this.mainHd.select('td').removeClass(sc);
1662 hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]);
1666 updateAllColumnWidths : function(){
1667 var tw = this.getTotalWidth(),
1668 clen = this.cm.getColumnCount(),
1673 for(i = 0; i < clen; i++){
1674 ws[i] = this.getColumnWidth(i);
1677 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1678 this.innerHd.firstChild.firstChild.style.width = tw;
1679 this.mainBody.dom.style.width = tw;
1681 for(i = 0; i < clen; i++){
1682 var hd = this.getHeaderCell(i);
1683 hd.style.width = ws[i];
1686 var ns = this.getRows(), row, trow;
1687 for(i = 0, len = ns.length; i < len; i++){
1689 row.style.width = tw;
1691 row.firstChild.style.width = tw;
1692 trow = row.firstChild.rows[0];
1693 for (var j = 0; j < clen; j++) {
1694 trow.childNodes[j].style.width = ws[j];
1699 this.onAllColumnWidthsUpdated(ws, tw);
1703 updateColumnWidth : function(col, width){
1704 var w = this.getColumnWidth(col);
1705 var tw = this.getTotalWidth();
1706 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1707 this.innerHd.firstChild.firstChild.style.width = tw;
1708 this.mainBody.dom.style.width = tw;
1709 var hd = this.getHeaderCell(col);
1712 var ns = this.getRows(), row;
1713 for(var i = 0, len = ns.length; i < len; i++){
1715 row.style.width = tw;
1717 row.firstChild.style.width = tw;
1718 row.firstChild.rows[0].childNodes[col].style.width = w;
1722 this.onColumnWidthUpdated(col, w, tw);
1726 updateColumnHidden : function(col, hidden){
1727 var tw = this.getTotalWidth();
1728 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1729 this.innerHd.firstChild.firstChild.style.width = tw;
1730 this.mainBody.dom.style.width = tw;
1731 var display = hidden ? 'none' : '';
1733 var hd = this.getHeaderCell(col);
1734 hd.style.display = display;
1736 var ns = this.getRows(), row;
1737 for(var i = 0, len = ns.length; i < len; i++){
1739 row.style.width = tw;
1741 row.firstChild.style.width = tw;
1742 row.firstChild.rows[0].childNodes[col].style.display = display;
1746 this.onColumnHiddenUpdated(col, hidden, tw);
1747 delete this.lastViewWidth; // force recalc
1753 * Renders all of the rows to a string buffer and returns the string. This is called internally
1754 * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM.
1755 * @param {Array} columns The column data acquired from getColumnData.
1756 * @param {Array} records The array of records to render
1757 * @param {Ext.data.Store} store The store to render the rows from
1758 * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of
1759 * the rows so this is used to maintain logic for striping etc
1760 * @param {Number} colCount The total number of columns in the column model
1761 * @param {Boolean} stripe True to stripe the rows
1762 * @return {String} A string containing the HTML for the rendered rows
1764 doRender : function(columns, records, store, startRow, colCount, stripe) {
1765 var templates = this.templates,
1766 cellTemplate = templates.cell,
1767 rowTemplate = templates.row,
1768 last = colCount - 1;
1770 var tstyle = 'width:' + this.getTotalWidth() + ';';
1775 rowParams = {tstyle: tstyle},
1780 //build up each row's HTML
1781 for (var j = 0, len = records.length; j < len; j++) {
1782 record = records[j];
1785 var rowIndex = j + startRow;
1787 //build up each column's HTML
1788 for (var i = 0; i < colCount; i++) {
1789 column = columns[i];
1791 meta.id = column.id;
1792 meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
1793 meta.attr = meta.cellAttr = '';
1794 meta.style = column.style;
1795 meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
1797 if (Ext.isEmpty(meta.value)) {
1798 meta.value = ' ';
1801 if (this.markDirty && record.dirty && Ext.isDefined(record.modified[column.name])) {
1802 meta.css += ' x-grid3-dirty-cell';
1805 colBuffer[colBuffer.length] = cellTemplate.apply(meta);
1808 //set up row striping and row dirtiness CSS classes
1811 if (stripe && ((rowIndex + 1) % 2 === 0)) {
1812 alt[0] = 'x-grid3-row-alt';
1816 alt[1] = ' x-grid3-dirty-row';
1819 rowParams.cols = colCount;
1821 if (this.getRowClass) {
1822 alt[2] = this.getRowClass(record, rowIndex, rowParams, store);
1825 rowParams.alt = alt.join(' ');
1826 rowParams.cells = colBuffer.join('');
1828 rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams);
1831 return rowBuffer.join('');
1835 processRows : function(startRow, skipStripe) {
1836 if (!this.ds || this.ds.getCount() < 1) {
1840 var rows = this.getRows(),
1844 skipStripe = skipStripe || !this.grid.stripeRows;
1845 startRow = startRow || 0;
1847 for (i = 0; i<len; i++) {
1852 r.className = r.className.replace(this.rowClsRe, ' ');
1853 if ((i + 1) % 2 === 0){
1854 r.className += ' x-grid3-row-alt';
1860 // add first/last-row classes
1861 if (startRow === 0) {
1862 Ext.fly(rows[0]).addClass(this.firstRowCls);
1865 Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
1868 afterRender : function(){
1869 if(!this.ds || !this.cm){
1872 this.mainBody.dom.innerHTML = this.renderRows() || ' ';
1873 this.processRows(0, true);
1875 if(this.deferEmptyText !== true){
1876 this.applyEmptyText();
1878 this.grid.fireEvent('viewready', this.grid);
1883 * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not
1884 * render rows from the store, just the surrounding UI elements. It also sets up listeners on the UI elements
1885 * and sets up options like column menus, moving and resizing.
1887 renderUI : function() {
1888 var templates = this.templates,
1889 header = this.renderHeaders(),
1890 body = templates.body.apply({rows:' '});
1892 var html = templates.master.apply({
1895 ostyle: 'width:' + this.getOffsetWidth() + ';',
1896 bstyle: 'width:' + this.getTotalWidth() + ';'
1901 g.getGridEl().dom.innerHTML = html;
1903 this.initElements();
1905 // get mousedowns early
1906 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
1910 mouseover: this.handleHdOver,
1911 mouseout : this.handleHdOut,
1912 mousemove: this.handleHdMove
1915 this.scroller.on('scroll', this.syncScroll, this);
1916 if (g.enableColumnResize !== false) {
1917 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
1920 if (g.enableColumnMove) {
1921 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
1922 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
1925 if (g.enableHdMenu !== false) {
1926 this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
1928 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
1929 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
1932 if (g.enableColumnHide !== false) {
1933 this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
1936 beforeshow: this.beforeColMenuShow,
1937 itemclick : this.handleHdMenuClick
1939 this.hmenu.add('-', {
1942 text: this.columnsText,
1944 iconCls: 'x-cols-icon'
1948 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
1951 if (g.trackMouseOver) {
1954 mouseover: this.onRowOver,
1955 mouseout : this.onRowOut
1959 if (g.enableDragDrop || g.enableDrag) {
1960 this.dragZone = new Ext.grid.GridDragZone(g, {
1961 ddGroup : g.ddGroup || 'GridDD'
1965 this.updateHeaderSortState();
1969 processEvent : function(name, e) {
1970 var t = e.getTarget(),
1972 header = this.findHeaderIndex(t);
1973 g.fireEvent(name, e);
1974 if (header !== false) {
1975 g.fireEvent('header' + name, g, header, e);
1977 var row = this.findRowIndex(t),
1980 if (row !== false) {
1981 g.fireEvent('row' + name, g, row, e);
1982 cell = this.findCellIndex(t);
1983 if (cell !== false) {
1984 g.fireEvent('cell' + name, g, row, cell, e);
1986 body = this.findRowBody(t);
1988 g.fireEvent('rowbody' + name, g, row, e);
1992 g.fireEvent('container' + name, g, e);
1998 layout : function() {
2000 return; // not rendered
2003 var c = g.getGridEl();
2004 var csize = c.getSize(true);
2005 var vw = csize.width;
2007 if(!g.hideHeaders && (vw < 20 || csize.height < 20)){ // display: none?
2012 this.scroller.dom.style.overflow = 'visible';
2014 this.scroller.dom.style.position = 'static';
2017 this.el.setSize(csize.width, csize.height);
2019 var hdHeight = this.mainHd.getHeight();
2020 var vh = csize.height - (hdHeight);
2022 this.scroller.setSize(vw, vh);
2024 this.innerHd.style.width = (vw)+'px';
2028 if(this.lastViewWidth != vw){
2029 this.fitColumns(false, false);
2030 this.lastViewWidth = vw;
2034 this.syncHeaderScroll();
2036 this.onLayout(vw, vh);
2039 // template functions for subclasses and plugins
2040 // these functions include precalculated values
2041 onLayout : function(vw, vh){
2045 onColumnWidthUpdated : function(col, w, tw){
2049 onAllColumnWidthsUpdated : function(ws, tw){
2053 onColumnHiddenUpdated : function(col, hidden, tw){
2057 updateColumnText : function(col, text){
2061 afterMove : function(colIndex){
2065 /* ----------------------------------- Core Specific -------------------------------------------*/
2067 init : function(grid){
2070 this.initTemplates();
2071 this.initData(grid.store, grid.colModel);
2076 getColumnId : function(index){
2077 return this.cm.getColumnId(index);
2081 getOffsetWidth : function() {
2082 return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
2085 getScrollOffset: function(){
2086 return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
2091 * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just
2093 * @return {String} Rendered header row
2095 renderHeaders : function() {
2097 ts = this.templates,
2101 len = cm.getColumnCount(),
2104 for (var i = 0; i < len; i++) {
2105 p.id = cm.getColumnId(i);
2106 p.value = cm.getColumnHeader(i) || '';
2107 p.style = this.getColumnStyle(i, true);
2108 p.tooltip = this.getColumnTooltip(i);
2109 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
2111 if (cm.config[i].align == 'right') {
2112 p.istyle = 'padding-right:16px';
2116 cb[cb.length] = ct.apply(p);
2118 return ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'});
2122 getColumnTooltip : function(i){
2123 var tt = this.cm.getColumnTooltip(i);
2125 if(Ext.QuickTips.isEnabled()){
2126 return 'ext:qtip="'+tt+'"';
2128 return 'title="'+tt+'"';
2135 beforeUpdate : function(){
2136 this.grid.stopEditing(true);
2140 updateHeaders : function(){
2141 this.innerHd.firstChild.innerHTML = this.renderHeaders();
2142 this.innerHd.firstChild.style.width = this.getOffsetWidth();
2143 this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
2147 * Focuses the specified row.
2148 * @param {Number} row The row index
2150 focusRow : function(row){
2151 this.focusCell(row, 0, false);
2155 * Focuses the specified cell.
2156 * @param {Number} row The row index
2157 * @param {Number} col The column index
2159 focusCell : function(row, col, hscroll){
2160 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
2162 this.focusEl.focus();
2164 this.focusEl.focus.defer(1, this.focusEl);
2168 resolveCell : function(row, col, hscroll){
2169 if(!Ext.isNumber(row)){
2175 if(row < 0 || row >= this.ds.getCount()){
2178 col = (col !== undefined ? col : 0);
2180 var rowEl = this.getRow(row),
2182 colCount = cm.getColumnCount(),
2184 if(!(hscroll === false && col === 0)){
2185 while(col < colCount && cm.isHidden(col)){
2188 cellEl = this.getCell(row, col);
2191 return {row: rowEl, cell: cellEl};
2194 getResolvedXY : function(resolved){
2198 var s = this.scroller.dom, c = resolved.cell, r = resolved.row;
2199 return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()];
2202 syncFocusEl : function(row, col, hscroll){
2204 if(!Ext.isArray(xy)){
2205 row = Math.min(row, Math.max(0, this.getRows().length-1));
2209 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
2211 this.focusEl.setXY(xy||this.scroller.getXY());
2214 ensureVisible : function(row, col, hscroll){
2215 var resolved = this.resolveCell(row, col, hscroll);
2216 if(!resolved || !resolved.row){
2220 var rowEl = resolved.row,
2221 cellEl = resolved.cell,
2222 c = this.scroller.dom,
2227 while(p && p != stop){
2228 ctop += p.offsetTop;
2232 ctop -= this.mainHd.dom.offsetHeight;
2233 stop = parseInt(c.scrollTop, 10);
2235 var cbot = ctop + rowEl.offsetHeight,
2236 ch = c.clientHeight,
2242 }else if(cbot > sbot){
2243 c.scrollTop = cbot-ch;
2246 if(hscroll !== false){
2247 var cleft = parseInt(cellEl.offsetLeft, 10);
2248 var cright = cleft + cellEl.offsetWidth;
2250 var sleft = parseInt(c.scrollLeft, 10);
2251 var sright = sleft + c.clientWidth;
2253 c.scrollLeft = cleft;
2254 }else if(cright > sright){
2255 c.scrollLeft = cright-c.clientWidth;
2258 return this.getResolvedXY(resolved);
2262 insertRows : function(dm, firstRow, lastRow, isUpdate) {
2263 var last = dm.getCount() - 1;
2264 if( !isUpdate && firstRow === 0 && lastRow >= last) {
2265 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
2267 this.fireEvent('rowsinserted', this, firstRow, lastRow);
2270 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
2272 var html = this.renderRows(firstRow, lastRow),
2273 before = this.getRow(firstRow);
2276 Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
2278 Ext.DomHelper.insertHtml('beforeBegin', before, html);
2280 var r = this.getRow(last - 1);
2282 Ext.fly(r).removeClass(this.lastRowCls);
2284 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
2287 this.fireEvent('rowsinserted', this, firstRow, lastRow);
2288 this.processRows(firstRow);
2289 } else if (firstRow === 0 || firstRow >= last) {
2290 //ensure first/last row is kept after an update.
2291 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
2294 this.syncFocusEl(firstRow);
2298 deleteRows : function(dm, firstRow, lastRow){
2299 if(dm.getRowCount()<1){
2302 this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
2304 this.removeRows(firstRow, lastRow);
2306 this.processRows(firstRow);
2307 this.fireEvent('rowsdeleted', this, firstRow, lastRow);
2312 getColumnStyle : function(col, isHeader){
2313 var style = !isHeader ? (this.cm.config[col].css || '') : '';
2314 style += 'width:'+this.getColumnWidth(col)+';';
2315 if(this.cm.isHidden(col)){
2316 style += 'display:none;';
2318 var align = this.cm.config[col].align;
2320 style += 'text-align:'+align+';';
2326 getColumnWidth : function(col){
2327 var w = this.cm.getColumnWidth(col);
2328 if(Ext.isNumber(w)){
2329 return (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? w : (w - this.borderWidth > 0 ? w - this.borderWidth : 0)) + 'px';
2335 getTotalWidth : function(){
2336 return this.cm.getTotalWidth()+'px';
2340 fitColumns : function(preventRefresh, onlyExpand, omitColumn){
2341 var cm = this.cm, i;
2342 var tw = cm.getTotalWidth(false);
2343 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
2345 if(aw < 20){ // not initialized, so don't screw up the default widths
2348 var extra = aw - tw;
2354 var vc = cm.getColumnCount(true);
2355 var ac = vc-(Ext.isNumber(omitColumn) ? 1 : 0);
2358 omitColumn = undefined;
2360 var colCount = cm.getColumnCount();
2365 for (i = 0; i < colCount; i++){
2366 if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
2367 w = cm.getColumnWidth(i);
2374 var frac = (aw - cm.getTotalWidth())/width;
2375 while (cols.length){
2378 cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
2381 if((tw = cm.getTotalWidth(false)) > aw){
2382 var adjustCol = ac != vc ? omitColumn : extraCol;
2383 cm.setColumnWidth(adjustCol, Math.max(1,
2384 cm.getColumnWidth(adjustCol)- (tw-aw)), true);
2387 if(preventRefresh !== true){
2388 this.updateAllColumnWidths();
2396 autoExpand : function(preventUpdate){
2397 var g = this.grid, cm = this.cm;
2398 if(!this.userResized && g.autoExpandColumn){
2399 var tw = cm.getTotalWidth(false);
2400 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
2402 var ci = cm.getIndexById(g.autoExpandColumn);
2403 var currentWidth = cm.getColumnWidth(ci);
2404 var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
2405 if(cw != currentWidth){
2406 cm.setColumnWidth(ci, cw, true);
2407 if(preventUpdate !== true){
2408 this.updateColumnWidth(ci, cw);
2417 * Returns an array of column configurations - one for each column
2418 * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
2420 getColumnData : function(){
2421 // build a map for all the columns
2424 colCount = cm.getColumnCount();
2426 for (var i = 0; i < colCount; i++) {
2427 var name = cm.getDataIndex(i);
2430 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
2431 renderer: cm.getRenderer(i),
2432 scope : cm.getRendererScope(i),
2433 id : cm.getColumnId(i),
2434 style : this.getColumnStyle(i)
2442 renderRows : function(startRow, endRow){
2443 // pull in all the crap needed to render rows
2444 var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
2445 var colCount = cm.getColumnCount();
2447 if(ds.getCount() < 1){
2451 var cs = this.getColumnData();
2453 startRow = startRow || 0;
2454 endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow;
2456 // records to render
2457 var rs = ds.getRange(startRow, endRow);
2459 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
2463 renderBody : function(){
2464 var markup = this.renderRows() || ' ';
2465 return this.templates.body.apply({rows: markup});
2469 refreshRow : function(record){
2470 var ds = this.ds, index;
2471 if(Ext.isNumber(record)){
2473 record = ds.getAt(index);
2478 index = ds.indexOf(record);
2483 this.insertRows(ds, index, index, true);
2484 this.getRow(index).rowIndex = index;
2485 this.onRemove(ds, record, index+1, true);
2486 this.fireEvent('rowupdated', this, index, record);
2490 * Refreshs the grid UI
2491 * @param {Boolean} headersToo (optional) True to also refresh the headers
2493 refresh : function(headersToo){
2494 this.fireEvent('beforerefresh', this);
2495 this.grid.stopEditing(true);
2497 var result = this.renderBody();
2498 this.mainBody.update(result).setWidth(this.getTotalWidth());
2499 if(headersToo === true){
2500 this.updateHeaders();
2501 this.updateHeaderSortState();
2503 this.processRows(0, true);
2505 this.applyEmptyText();
2506 this.fireEvent('refresh', this);
2511 * Displays the configured emptyText if there are currently no rows to display
2513 applyEmptyText : function(){
2514 if(this.emptyText && !this.hasRows()){
2515 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
2521 * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
2522 * if the sorting has changed since this function was last run.
2524 updateHeaderSortState : function(){
2525 var state = this.ds.getSortState();
2530 if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
2531 this.grid.fireEvent('sortchange', this.grid, state);
2534 this.sortState = state;
2536 var sortColumn = this.cm.findColumnIndex(state.field);
2537 if (sortColumn != -1){
2538 var sortDir = state.direction;
2539 this.updateSortIcon(sortColumn, sortDir);
2545 * Removes any sorting indicator classes from the column headers
2547 clearHeaderSortState : function(){
2548 if (!this.sortState) {
2551 this.grid.fireEvent('sortchange', this.grid, null);
2552 this.mainHd.select('td').removeClass(this.sortClasses);
2553 delete this.sortState;
2557 destroy : function(){
2558 if (this.scrollToTopTask && this.scrollToTopTask.cancel){
2559 this.scrollToTopTask.cancel();
2562 Ext.menu.MenuMgr.unregister(this.colMenu);
2563 this.colMenu.destroy();
2564 delete this.colMenu;
2567 Ext.menu.MenuMgr.unregister(this.hmenu);
2568 this.hmenu.destroy();
2572 this.initData(null, null);
2573 this.purgeListeners();
2574 Ext.fly(this.innerHd).un("click", this.handleHdDown, this);
2576 if(this.grid.enableColumnMove){
2579 this.columnDrag.proxy.ghost,
2580 this.columnDrag.proxy.el,
2582 this.columnDrop.proxyTop,
2583 this.columnDrop.proxyBottom,
2584 this.columnDrag.dragData.ddel,
2585 this.columnDrag.dragData.header
2587 if (this.columnDrag.proxy.anim) {
2588 Ext.destroy(this.columnDrag.proxy.anim);
2590 delete this.columnDrag.proxy.ghost;
2591 delete this.columnDrag.dragData.ddel;
2592 delete this.columnDrag.dragData.header;
2593 this.columnDrag.destroy();
2594 delete Ext.dd.DDM.locationCache[this.columnDrag.id];
2595 delete this.columnDrag._domRef;
2597 delete this.columnDrop.proxyTop;
2598 delete this.columnDrop.proxyBottom;
2599 this.columnDrop.destroy();
2600 delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id];
2601 delete this.columnDrop._domRef;
2602 delete Ext.dd.DDM.ids[this.columnDrop.ddGroup];
2605 if (this.splitZone){ // enableColumnResize
2606 this.splitZone.destroy();
2607 delete this.splitZone._domRef;
2608 delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id];
2611 Ext.fly(this.innerHd).removeAllListeners();
2612 Ext.removeNode(this.innerHd);
2613 delete this.innerHd;
2630 delete this.grid.container;
2633 this.dragZone.destroy();
2636 Ext.dd.DDM.currentTarget = null;
2637 delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id];
2639 Ext.EventManager.removeResizeListener(this.onWindowResize, this);
2643 onDenyColumnHide : function(){
2648 render : function(){
2650 var ct = this.grid.ownerCt;
2651 if (ct && ct.getLayout()){
2652 ct.on('afterlayout', function(){
2653 this.fitColumns(true, true);
2654 this.updateHeaders();
2655 }, this, {single: true});
2657 this.fitColumns(true, true);
2659 }else if(this.forceFit){
2660 this.fitColumns(true, false);
2661 }else if(this.grid.autoExpandColumn){
2662 this.autoExpand(true);
2668 /* --------------------------------- Model Events and Handlers --------------------------------*/
2670 initData : function(ds, cm){
2672 this.ds.un('load', this.onLoad, this);
2673 this.ds.un('datachanged', this.onDataChange, this);
2674 this.ds.un('add', this.onAdd, this);
2675 this.ds.un('remove', this.onRemove, this);
2676 this.ds.un('update', this.onUpdate, this);
2677 this.ds.un('clear', this.onClear, this);
2678 if(this.ds !== ds && this.ds.autoDestroy){
2686 datachanged: this.onDataChange,
2688 remove: this.onRemove,
2689 update: this.onUpdate,
2696 this.cm.un('configchange', this.onColConfigChange, this);
2697 this.cm.un('widthchange', this.onColWidthChange, this);
2698 this.cm.un('headerchange', this.onHeaderChange, this);
2699 this.cm.un('hiddenchange', this.onHiddenChange, this);
2700 this.cm.un('columnmoved', this.onColumnMove, this);
2703 delete this.lastViewWidth;
2706 configchange: this.onColConfigChange,
2707 widthchange: this.onColWidthChange,
2708 headerchange: this.onHeaderChange,
2709 hiddenchange: this.onHiddenChange,
2710 columnmoved: this.onColumnMove
2717 onDataChange : function(){
2719 this.updateHeaderSortState();
2720 this.syncFocusEl(0);
2724 onClear : function(){
2726 this.syncFocusEl(0);
2730 onUpdate : function(ds, record){
2731 this.refreshRow(record);
2735 onAdd : function(ds, records, index){
2736 this.insertRows(ds, index, index + (records.length-1));
2740 onRemove : function(ds, record, index, isUpdate){
2741 if(isUpdate !== true){
2742 this.fireEvent('beforerowremoved', this, index, record);
2744 this.removeRow(index);
2745 if(isUpdate !== true){
2746 this.processRows(index);
2747 this.applyEmptyText();
2748 this.fireEvent('rowremoved', this, index, record);
2753 onLoad : function(){
2755 if (!this.scrollToTopTask) {
2756 this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
2758 this.scrollToTopTask.delay(1);
2765 onColWidthChange : function(cm, col, width){
2766 this.updateColumnWidth(col, width);
2770 onHeaderChange : function(cm, col, text){
2771 this.updateHeaders();
2775 onHiddenChange : function(cm, col, hidden){
2776 this.updateColumnHidden(col, hidden);
2780 onColumnMove : function(cm, oldIndex, newIndex){
2781 this.indexMap = null;
2782 var s = this.getScrollState();
2784 this.restoreScroll(s);
2785 this.afterMove(newIndex);
2786 this.grid.fireEvent('columnmove', oldIndex, newIndex);
2790 onColConfigChange : function(){
2791 delete this.lastViewWidth;
2792 this.indexMap = null;
2796 /* -------------------- UI Events and Handlers ------------------------------ */
2798 initUI : function(grid){
2799 grid.on('headerclick', this.onHeaderClick, this);
2803 initEvents : function(){
2807 onHeaderClick : function(g, index){
2808 if(this.headersDisabled || !this.cm.isSortable(index)){
2811 g.stopEditing(true);
2812 g.store.sort(this.cm.getDataIndex(index));
2816 onRowOver : function(e, t){
2818 if((row = this.findRowIndex(t)) !== false){
2819 this.addRowClass(row, 'x-grid3-row-over');
2824 onRowOut : function(e, t){
2826 if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
2827 this.removeRowClass(row, 'x-grid3-row-over');
2832 handleWheel : function(e){
2833 e.stopPropagation();
2837 onRowSelect : function(row){
2838 this.addRowClass(row, this.selectedRowClass);
2842 onRowDeselect : function(row){
2843 this.removeRowClass(row, this.selectedRowClass);
2847 onCellSelect : function(row, col){
2848 var cell = this.getCell(row, col);
2850 this.fly(cell).addClass('x-grid3-cell-selected');
2855 onCellDeselect : function(row, col){
2856 var cell = this.getCell(row, col);
2858 this.fly(cell).removeClass('x-grid3-cell-selected');
2863 onColumnSplitterMoved : function(i, w){
2864 this.userResized = true;
2865 var cm = this.grid.colModel;
2866 cm.setColumnWidth(i, w, true);
2869 this.fitColumns(true, false, i);
2870 this.updateAllColumnWidths();
2872 this.updateColumnWidth(i, w);
2873 this.syncHeaderScroll();
2876 this.grid.fireEvent('columnresize', i, w);
2880 handleHdMenuClick : function(item){
2881 var index = this.hdCtxIndex,
2884 id = item.getItemId();
2887 ds.sort(cm.getDataIndex(index), 'ASC');
2890 ds.sort(cm.getDataIndex(index), 'DESC');
2893 index = cm.getIndexById(id.substr(4));
2895 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
2896 this.onDenyColumnHide();
2899 cm.setHidden(index, item.checked);
2906 isHideableColumn : function(c){
2911 beforeColMenuShow : function(){
2912 var cm = this.cm, colCount = cm.getColumnCount();
2913 this.colMenu.removeAll();
2914 for(var i = 0; i < colCount; i++){
2915 if(cm.config[i].hideable !== false){
2916 this.colMenu.add(new Ext.menu.CheckItem({
2917 itemId: 'col-'+cm.getColumnId(i),
2918 text: cm.getColumnHeader(i),
2919 checked: !cm.isHidden(i),
2921 disabled: cm.config[i].hideable === false
2928 handleHdDown : function(e, t){
2929 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
2931 var hd = this.findHeaderCell(t);
2932 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
2933 var index = this.getCellIndex(hd);
2934 this.hdCtxIndex = index;
2935 var ms = this.hmenu.items, cm = this.cm;
2936 ms.get('asc').setDisabled(!cm.isSortable(index));
2937 ms.get('desc').setDisabled(!cm.isSortable(index));
2938 this.hmenu.on('hide', function(){
2939 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
2940 }, this, {single:true});
2941 this.hmenu.show(t, 'tl-bl?');
2946 handleHdOver : function(e, t){
2947 var hd = this.findHeaderCell(t);
2948 if(hd && !this.headersDisabled){
2949 this.activeHdRef = t;
2950 this.activeHdIndex = this.getCellIndex(hd);
2951 var fly = this.fly(hd);
2952 this.activeHdRegion = fly.getRegion();
2953 if(!this.cm.isMenuDisabled(this.activeHdIndex)){
2954 fly.addClass('x-grid3-hd-over');
2955 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
2956 if(this.activeHdBtn){
2957 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
2964 handleHdMove : function(e, t){
2965 var hd = this.findHeaderCell(this.activeHdRef);
2966 if(hd && !this.headersDisabled){
2967 var hw = this.splitHandleWidth || 5,
2968 r = this.activeHdRegion,
2972 if(this.grid.enableColumnResize !== false){
2973 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
2974 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
2975 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
2976 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
2984 handleHdOut : function(e, t){
2985 var hd = this.findHeaderCell(t);
2986 if(hd && (!Ext.isIE || !e.within(hd, true))){
2987 this.activeHdRef = null;
2988 this.fly(hd).removeClass('x-grid3-hd-over');
2989 hd.style.cursor = '';
2994 hasRows : function(){
2995 var fc = this.mainBody.dom.firstChild;
2996 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
3000 bind : function(d, c){
3001 this.initData(d, c);
3007 // This is a support class used internally by the Grid components
3008 Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
3010 constructor: function(grid, hd){
3012 this.view = grid.getView();
3013 this.marker = this.view.resizeMarker;
3014 this.proxy = this.view.resizeProxy;
3015 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
3016 'gridSplitters' + this.grid.getGridEl().id, {
3017 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
3019 this.scroll = false;
3020 this.hw = this.view.splitHandleWidth || 5;
3023 b4StartDrag : function(x, y){
3024 this.dragHeadersDisabled = this.view.headersDisabled;
3025 this.view.headersDisabled = true;
3026 var h = this.view.mainWrap.getHeight();
3027 this.marker.setHeight(h);
3029 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
3030 this.proxy.setHeight(h);
3031 var w = this.cm.getColumnWidth(this.cellIndex),
3032 minw = Math.max(w-this.grid.minColumnWidth, 0);
3033 this.resetConstraints();
3034 this.setXConstraint(minw, 1000);
3035 this.setYConstraint(0, 0);
3036 this.minX = x - minw;
3037 this.maxX = x + 1000;
3039 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
3042 allowHeaderDrag : function(e){
3046 handleMouseDown : function(e){
3047 var t = this.view.findHeaderCell(e.getTarget());
3048 if(t && this.allowHeaderDrag(e)){
3049 var xy = this.view.fly(t).getXY(),
3052 exy = e.getXY(), ex = exy[0],
3053 w = t.offsetWidth, adjust = false;
3055 if((ex - x) <= this.hw){
3057 }else if((x+w) - ex <= this.hw){
3060 if(adjust !== false){
3061 this.cm = this.grid.colModel;
3062 var ci = this.view.getCellIndex(t);
3064 if (ci + adjust < 0) {
3067 while(this.cm.isHidden(ci+adjust)){
3074 this.cellIndex = ci+adjust;
3076 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
3077 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
3079 }else if(this.view.columnDrag){
3080 this.view.columnDrag.callHandleMouseDown(e);
3085 endDrag : function(e){
3088 endX = Math.max(this.minX, e.getPageX()),
3089 diff = endX - this.startPos,
3090 disabled = this.dragHeadersDisabled;
3092 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
3093 setTimeout(function(){
3094 v.headersDisabled = disabled;
3098 autoOffset : function(){
3103 // This is a support class used internally by the Grid components
3104 Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
3107 constructor : function(grid, hd, hd2){
3109 this.view = grid.getView();
3110 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
3111 Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
3113 this.setHandleElId(Ext.id(hd));
3114 this.setOuterHandleElId(Ext.id(hd2));
3116 this.scroll = false;
3119 getDragData : function(e){
3120 var t = Ext.lib.Event.getTarget(e),
3121 h = this.view.findHeaderCell(t);
3123 return {ddel: h.firstChild, header:h};
3128 onInitDrag : function(e){
3129 // keep the value here so we can restore it;
3130 this.dragHeadersDisabled = this.view.headersDisabled;
3131 this.view.headersDisabled = true;
3132 var clone = this.dragData.ddel.cloneNode(true);
3133 clone.id = Ext.id();
3134 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
3135 this.proxy.update(clone);
3139 afterValidDrop : function(){
3140 this.completeDrop();
3143 afterInvalidDrop : function(){
3144 this.completeDrop();
3147 completeDrop: function(){
3149 disabled = this.dragHeadersDisabled;
3150 setTimeout(function(){
3151 v.headersDisabled = disabled;
3157 // This is a support class used internally by the Grid components
3158 Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
3159 proxyOffsets : [-4, -9],
3160 fly: Ext.Element.fly,
3162 constructor : function(grid, hd, hd2){
3164 this.view = grid.getView();
3165 // split the proxies so they don't interfere with mouse events
3166 this.proxyTop = Ext.DomHelper.append(document.body, {
3167 cls:"col-move-top", html:" "
3169 this.proxyBottom = Ext.DomHelper.append(document.body, {
3170 cls:"col-move-bottom", html:" "
3172 this.proxyTop.hide = this.proxyBottom.hide = function(){
3173 this.setLeftTop(-100,-100);
3174 this.setStyle("visibility", "hidden");
3176 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
3177 // temporarily disabled
3178 //Ext.dd.ScrollManager.register(this.view.scroller.dom);
3179 Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
3182 getTargetFromEvent : function(e){
3183 var t = Ext.lib.Event.getTarget(e),
3184 cindex = this.view.findCellIndex(t);
3185 if(cindex !== false){
3186 return this.view.getHeaderCell(cindex);
3190 nextVisible : function(h){
3191 var v = this.view, cm = this.grid.colModel;
3194 if(!cm.isHidden(v.getCellIndex(h))){
3202 prevVisible : function(h){
3203 var v = this.view, cm = this.grid.colModel;
3206 if(!cm.isHidden(v.getCellIndex(h))){
3214 positionIndicator : function(h, n, e){
3215 var x = Ext.lib.Event.getPageX(e),
3216 r = Ext.lib.Dom.getRegion(n.firstChild),
3219 py = r.top + this.proxyOffsets[1];
3220 if((r.right - x) <= (r.right-r.left)/2){
3221 px = r.right+this.view.borderWidth;
3228 if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
3232 px += this.proxyOffsets[0];
3233 this.proxyTop.setLeftTop(px, py);
3234 this.proxyTop.show();
3235 if(!this.bottomOffset){
3236 this.bottomOffset = this.view.mainHd.getHeight();
3238 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
3239 this.proxyBottom.show();
3243 onNodeEnter : function(n, dd, e, data){
3244 if(data.header != n){
3245 this.positionIndicator(data.header, n, e);
3249 onNodeOver : function(n, dd, e, data){
3251 if(data.header != n){
3252 result = this.positionIndicator(data.header, n, e);
3255 this.proxyTop.hide();
3256 this.proxyBottom.hide();
3258 return result ? this.dropAllowed : this.dropNotAllowed;
3261 onNodeOut : function(n, dd, e, data){
3262 this.proxyTop.hide();
3263 this.proxyBottom.hide();
3266 onNodeDrop : function(n, dd, e, data){
3267 var h = data.header;
3269 var cm = this.grid.colModel,
3270 x = Ext.lib.Event.getPageX(e),
3271 r = Ext.lib.Dom.getRegion(n.firstChild),
3272 pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before",
3273 oldIndex = this.view.getCellIndex(h),
3274 newIndex = this.view.getCellIndex(n);
3278 if(oldIndex < newIndex){
3281 cm.moveColumn(oldIndex, newIndex);
3288 Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
3290 constructor : function(grid, hd){
3291 Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
3292 this.proxy.el.addClass('x-grid3-col-dd');
3295 handleMouseDown : function(e){
3298 callHandleMouseDown : function(e){
3299 Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
3302 // This is a support class used internally by the Grid components
3303 Ext.grid.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
3304 fly: Ext.Element.fly,
3306 constructor : function(grid, hd, hd2){
3308 this.view = grid.getView();
3309 this.proxy = this.view.resizeProxy;
3310 Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
3311 "gridSplitters" + this.grid.getGridEl().id, {
3312 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
3314 this.setHandleElId(Ext.id(hd));
3315 this.setOuterHandleElId(Ext.id(hd2));
3316 this.scroll = false;
3319 b4StartDrag : function(x, y){
3320 this.view.headersDisabled = true;
3321 this.proxy.setHeight(this.view.mainWrap.getHeight());
3322 var w = this.cm.getColumnWidth(this.cellIndex);
3323 var minw = Math.max(w-this.grid.minColumnWidth, 0);
3324 this.resetConstraints();
3325 this.setXConstraint(minw, 1000);
3326 this.setYConstraint(0, 0);
3327 this.minX = x - minw;
3328 this.maxX = x + 1000;
3330 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
3334 handleMouseDown : function(e){
3335 var ev = Ext.EventObject.setEvent(e);
3336 var t = this.fly(ev.getTarget());
3337 if(t.hasClass("x-grid-split")){
3338 this.cellIndex = this.view.getCellIndex(t.dom);
3340 this.cm = this.grid.colModel;
3341 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
3342 Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
3347 endDrag : function(e){
3348 this.view.headersDisabled = false;
3349 var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e));
3350 var diff = endX - this.startPos;
3351 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
3354 autoOffset : function(){
3358 * @class Ext.grid.GridDragZone
3359 * @extends Ext.dd.DragZone
3360 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of two of the
3361 * template methods of DragZone to enable dragging of the selected rows of a GridPanel.</p>
3362 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's template method implementations of
3363 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
3364 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop}</p> are able
3365 * to process the {@link #getDragData data} which is provided.
3367 Ext.grid.GridDragZone = function(grid, config){
3368 this.view = grid.getView();
3369 Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
3370 this.scroll = false;
3372 this.ddel = document.createElement('div');
3373 this.ddel.className = 'x-grid-dd-wrap';
3376 Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, {
3380 * <p>The provided implementation of the getDragData method which collects the data to be dragged from the GridPanel on mousedown.</p>
3381 * <p>This data is available for processing in the {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
3382 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} methods of a cooperating {@link Ext.dd.DropZone DropZone}.</p>
3383 * <p>The data object contains the following properties:<ul>
3384 * <li><b>grid</b> : Ext.Grid.GridPanel<div class="sub-desc">The GridPanel from which the data is being dragged.</div></li>
3385 * <li><b>ddel</b> : htmlElement<div class="sub-desc">An htmlElement which provides the "picture" of the data being dragged.</div></li>
3386 * <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>
3387 * <li><b>selections</b> : Array<div class="sub-desc">An Array of the selected Records which are being dragged from the GridPanel.</div></li>
3390 getDragData : function(e){
3391 var t = Ext.lib.Event.getTarget(e);
3392 var rowIndex = this.view.findRowIndex(t);
3393 if(rowIndex !== false){
3394 var sm = this.grid.selModel;
3395 if(!sm.isSelected(rowIndex) || e.hasModifier()){
3396 sm.handleMouseDown(this.grid, rowIndex, e);
3398 return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
3404 * <p>The provided implementation of the onInitDrag method. Sets the <tt>innerHTML</tt> of the drag proxy which provides the "picture"
3405 * of the data being dragged.</p>
3406 * <p>The <tt>innerHTML</tt> data is found by calling the owning GridPanel's {@link Ext.grid.GridPanel#getDragDropText getDragDropText}.</p>
3408 onInitDrag : function(e){
3409 var data = this.dragData;
3410 this.ddel.innerHTML = this.grid.getDragDropText();
3411 this.proxy.update(this.ddel);
3416 * An empty immplementation. Implement this to provide behaviour after a repair of an invalid drop. An implementation might highlight
3417 * the selected rows to show that they have not been dragged.
3419 afterRepair : function(){
3420 this.dragging = false;
3424 * <p>An empty implementation. Implement this to provide coordinates for the drag proxy to slide back to after an invalid drop.</p>
3425 * <p>Called before a repair of an invalid drop to get the XY to animate to.</p>
3426 * @param {EventObject} e The mouse up event
3427 * @return {Array} The xy location (e.g. [100, 200])
3429 getRepairXY : function(e, data){
3433 onEndDrag : function(data, e){
3437 onValidDrop : function(dd, e, id){
3442 beforeInvalidDrop : function(e, id){
3447 * @class Ext.grid.ColumnModel
3448 * @extends Ext.util.Observable
3449 * <p>After the data has been read into the client side cache (<b>{@link Ext.data.Store Store}</b>),
3450 * the ColumnModel is used to configure how and what parts of that data will be displayed in the
3451 * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation
3452 * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.</p>
3453 * <p>Data is mapped into the store's records and then indexed into the ColumnModel using the
3454 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt>:</p>
3456 {data source} == mapping ==> {data store} == <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> ==> {ColumnModel}
3458 * <p>Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a
3459 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt> to specify how the data within
3460 * each record in the store is indexed into the ColumnModel.</p>
3461 * <p>There are two ways to initialize the ColumnModel class:</p>
3462 * <p><u>Initialization Method 1: an Array</u></p>
3464 var colModel = new Ext.grid.ColumnModel([
3465 { header: "Ticker", width: 60, sortable: true},
3466 { header: "Company Name", width: 150, sortable: true, id: 'company'},
3467 { header: "Market Cap.", width: 100, sortable: true},
3468 { header: "$ Sales", width: 100, sortable: true, renderer: money},
3469 { header: "Employees", width: 100, sortable: true, resizable: false}
3472 * <p>The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration
3473 * objects to define the initial layout / display of the columns in the Grid. The order of each
3474 * {@link Ext.grid.Column} column configuration object within the specified Array defines the initial
3475 * order of the column display. A Column's display may be initially hidden using the
3476 * <tt>{@link Ext.grid.Column#hidden hidden}</tt></b> config property (and then shown using the column
3477 * header menu). Fields that are not included in the ColumnModel will not be displayable at all.</p>
3478 * <p>How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the
3479 * {@link Ext.data.Store Store} the column draws its data from is configured through the
3480 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b>. If the
3481 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> is not explicitly defined (as shown in the
3482 * example above) it will use the column configuration's index in the Array as the index.</p>
3483 * <p>See <b><tt>{@link Ext.grid.Column}</tt></b> for additional configuration options for each column.</p>
3484 * <p><u>Initialization Method 2: an Object</u></p>
3485 * <p>In order to use configuration options from <tt>Ext.grid.ColumnModel</tt>, an Object may be used to
3486 * initialize the ColumnModel. The column configuration Array will be specified in the <tt><b>{@link #columns}</b></tt>
3487 * config property. The <tt><b>{@link #defaults}</b></tt> config property can be used to apply defaults
3488 * for all columns, e.g.:</p><pre><code>
3489 var colModel = new Ext.grid.ColumnModel({
3491 { header: "Ticker", width: 60, menuDisabled: false},
3492 { header: "Company Name", width: 150, id: 'company'},
3493 { header: "Market Cap."},
3494 { header: "$ Sales", renderer: money},
3495 { header: "Employees", resizable: false}
3503 {@link #hiddenchange}: function(cm, colIndex, hidden) {
3504 saveConfig(colIndex, hidden);
3509 * <p>In both examples above, the ability to apply a CSS class to all cells in a column (including the
3510 * header) is demonstrated through the use of the <b><tt>{@link Ext.grid.Column#id id}</tt></b> config
3511 * option. This column could be styled by including the following css:</p><pre><code>
3512 //add this css *after* the core css is loaded
3513 .x-grid3-td-company {
3514 color: red; // entire column will have red font
3516 // modify the header row only, adding an icon to the column header
3517 .x-grid3-hd-company {
3518 background: transparent
3519 url(../../resources/images/icons/silk/building.png)
3520 no-repeat 3px 3px ! important;
3524 * Note that the "Company Name" column could be specified as the
3525 * <b><tt>{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></b>.
3527 * @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify
3528 * a configuration Object (see introductory section discussion utilizing Initialization Method 2 above).
3530 Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
3532 * @cfg {Number} defaultWidth (optional) The width of columns which have no <tt>{@link #width}</tt>
3533 * specified (defaults to <tt>100</tt>). This property shall preferably be configured through the
3534 * <tt><b>{@link #defaults}</b></tt> config property.
3538 * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no
3539 * sortable specified (defaults to <tt>false</tt>). This property shall preferably be configured
3540 * through the <tt><b>{@link #defaults}</b></tt> config property.
3542 defaultSortable: false,
3544 * @cfg {Array} columns An Array of object literals. The config options defined by
3545 * <b>{@link Ext.grid.Column}</b> are the options which may appear in the object literal for each
3546 * individual column definition.
3549 * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column}
3550 * configuration options to all <tt><b>{@link #columns}</b></tt>. Configuration options specified with
3551 * individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>.
3554 constructor : function(config){
3556 * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
3557 * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
3563 Ext.apply(this, config);
3564 this.setConfig(config.columns, true);
3566 this.setConfig(config, true);
3570 * @event widthchange
3571 * Fires when the width of a column is programmaticially changed using
3572 * <code>{@link #setColumnWidth}</code>.
3573 * Note internal resizing suppresses the event from firing. See also
3574 * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>.
3575 * @param {ColumnModel} this
3576 * @param {Number} columnIndex The column index
3577 * @param {Number} newWidth The new width
3581 * @event headerchange
3582 * Fires when the text of a header changes.
3583 * @param {ColumnModel} this
3584 * @param {Number} columnIndex The column index
3585 * @param {String} newText The new header text
3589 * @event hiddenchange
3590 * Fires when a column is hidden or "unhidden".
3591 * @param {ColumnModel} this
3592 * @param {Number} columnIndex The column index
3593 * @param {Boolean} hidden true if hidden, false otherwise
3597 * @event columnmoved
3598 * Fires when a column is moved.
3599 * @param {ColumnModel} this
3600 * @param {Number} oldIndex
3601 * @param {Number} newIndex
3605 * @event configchange
3606 * Fires when the configuration is changed
3607 * @param {ColumnModel} this
3611 Ext.grid.ColumnModel.superclass.constructor.call(this);
3615 * Returns the id of the column at the specified index.
3616 * @param {Number} index The column index
3617 * @return {String} the id
3619 getColumnId : function(index){
3620 return this.config[index].id;
3623 getColumnAt : function(index){
3624 return this.config[index];
3628 * <p>Reconfigures this column model according to the passed Array of column definition objects.
3629 * For a description of the individual properties of a column definition object, see the
3630 * <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p>
3631 * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel}
3632 * using this ColumnModel will listen for this event and refresh its UI automatically.</p>
3633 * @param {Array} config Array of Column definition objects.
3634 * @param {Boolean} initial Specify <tt>true</tt> to bypass cleanup which deletes the <tt>totalWidth</tt>
3635 * and destroys existing editors.
3637 setConfig : function(config, initial){
3639 if(!initial){ // cleanup
3640 delete this.totalWidth;
3641 for(i = 0, len = this.config.length; i < len; i++){
3644 //check here, in case we have a special column like a CheckboxSelectionModel
3650 // backward compatibility
3651 this.defaults = Ext.apply({
3652 width: this.defaultWidth,
3653 sortable: this.defaultSortable
3656 this.config = config;
3659 for(i = 0, len = config.length; i < len; i++){
3660 c = Ext.applyIf(config[i], this.defaults);
3661 // if no id, create one using column's ordinal position
3662 if(Ext.isEmpty(c.id)){
3666 var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
3670 this.lookup[c.id] = c;
3673 this.fireEvent('configchange', this);
3678 * Returns the column for a specified id.
3679 * @param {String} id The column id
3680 * @return {Object} the column
3682 getColumnById : function(id){
3683 return this.lookup[id];
3687 * Returns the index for a specified column id.
3688 * @param {String} id The column id
3689 * @return {Number} the index, or -1 if not found
3691 getIndexById : function(id){
3692 for(var i = 0, len = this.config.length; i < len; i++){
3693 if(this.config[i].id == id){
3701 * Moves a column from one position to another.
3702 * @param {Number} oldIndex The index of the column to move.
3703 * @param {Number} newIndex The position at which to reinsert the coolumn.
3705 moveColumn : function(oldIndex, newIndex){
3706 var c = this.config[oldIndex];
3707 this.config.splice(oldIndex, 1);
3708 this.config.splice(newIndex, 0, c);
3709 this.dataMap = null;
3710 this.fireEvent("columnmoved", this, oldIndex, newIndex);
3714 * Returns the number of columns.
3715 * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.
3718 getColumnCount : function(visibleOnly){
3719 if(visibleOnly === true){
3721 for(var i = 0, len = this.config.length; i < len; i++){
3722 if(!this.isHidden(i)){
3728 return this.config.length;
3732 * Returns the column configs that return true by the passed function that is called
3733 * with (columnConfig, index)
3735 // returns an array of column config objects for all hidden columns
3736 var columns = grid.getColumnModel().getColumnsBy(function(c){
3740 * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must
3741 * return <code>true</code> if the column is to be included in the returned Array.
3742 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function
3743 * is executed. Defaults to this ColumnModel.
3744 * @return {Array} result
3746 getColumnsBy : function(fn, scope){
3748 for(var i = 0, len = this.config.length; i < len; i++){
3749 var c = this.config[i];
3750 if(fn.call(scope||this, c, i) === true){
3758 * Returns true if the specified column is sortable.
3759 * @param {Number} col The column index
3762 isSortable : function(col){
3763 return !!this.config[col].sortable;
3767 * Returns true if the specified column menu is disabled.
3768 * @param {Number} col The column index
3771 isMenuDisabled : function(col){
3772 return !!this.config[col].menuDisabled;
3776 * Returns the rendering (formatting) function defined for the column.
3777 * @param {Number} col The column index.
3778 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
3780 getRenderer : function(col){
3781 if(!this.config[col].renderer){
3782 return Ext.grid.ColumnModel.defaultRenderer;
3784 return this.config[col].renderer;
3787 getRendererScope : function(col){
3788 return this.config[col].scope;
3792 * Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
3793 * default formatting functions.
3794 * @param {Number} col The column index
3795 * @param {Function} fn The function to use to process the cell's raw data
3796 * to return HTML markup for the grid view. The render function is called with
3797 * the following parameters:<ul>
3798 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
3799 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
3800 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
3801 * <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
3802 * (e.g. 'style="color:red;"').</p></li></ul></p></li>
3803 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was extracted.</p></li>
3804 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
3805 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
3806 * <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>
3808 setRenderer : function(col, fn){
3809 this.config[col].renderer = fn;
3813 * Returns the width for the specified column.
3814 * @param {Number} col The column index
3817 getColumnWidth : function(col){
3818 return this.config[col].width;
3822 * Sets the width for a column.
3823 * @param {Number} col The column index
3824 * @param {Number} width The new width
3825 * @param {Boolean} suppressEvent True to suppress firing the <code>{@link #widthchange}</code>
3826 * event. Defaults to false.
3828 setColumnWidth : function(col, width, suppressEvent){
3829 this.config[col].width = width;
3830 this.totalWidth = null;
3832 this.fireEvent("widthchange", this, col, width);
3837 * Returns the total width of all columns.
3838 * @param {Boolean} includeHidden True to include hidden column widths
3841 getTotalWidth : function(includeHidden){
3842 if(!this.totalWidth){
3843 this.totalWidth = 0;
3844 for(var i = 0, len = this.config.length; i < len; i++){
3845 if(includeHidden || !this.isHidden(i)){
3846 this.totalWidth += this.getColumnWidth(i);
3850 return this.totalWidth;
3854 * Returns the header for the specified column.
3855 * @param {Number} col The column index
3858 getColumnHeader : function(col){
3859 return this.config[col].header;
3863 * Sets the header for a column.
3864 * @param {Number} col The column index
3865 * @param {String} header The new header
3867 setColumnHeader : function(col, header){
3868 this.config[col].header = header;
3869 this.fireEvent("headerchange", this, col, header);
3873 * Returns the tooltip for the specified column.
3874 * @param {Number} col The column index
3877 getColumnTooltip : function(col){
3878 return this.config[col].tooltip;
3881 * Sets the tooltip for a column.
3882 * @param {Number} col The column index
3883 * @param {String} tooltip The new tooltip
3885 setColumnTooltip : function(col, tooltip){
3886 this.config[col].tooltip = tooltip;
3890 * Returns the dataIndex for the specified column.
3892 // Get field name for the column
3893 var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
3895 * @param {Number} col The column index
3896 * @return {String} The column's dataIndex
3898 getDataIndex : function(col){
3899 return this.config[col].dataIndex;
3903 * Sets the dataIndex for a column.
3904 * @param {Number} col The column index
3905 * @param {String} dataIndex The new dataIndex
3907 setDataIndex : function(col, dataIndex){
3908 this.config[col].dataIndex = dataIndex;
3912 * Finds the index of the first matching column for the given dataIndex.
3913 * @param {String} col The dataIndex to find
3914 * @return {Number} The column index, or -1 if no match was found
3916 findColumnIndex : function(dataIndex){
3917 var c = this.config;
3918 for(var i = 0, len = c.length; i < len; i++){
3919 if(c[i].dataIndex == dataIndex){
3927 * Returns true if the cell is editable.
3929 var store = new Ext.data.Store({...});
3930 var colModel = new Ext.grid.ColumnModel({
3932 isCellEditable: function(col, row) {
3933 var record = store.getAt(row);
3934 if (record.get('readonly')) { // replace with your condition
3937 return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
3940 var grid = new Ext.grid.GridPanel({
3946 * @param {Number} colIndex The column index
3947 * @param {Number} rowIndex The row index
3950 isCellEditable : function(colIndex, rowIndex){
3951 var c = this.config[colIndex],
3955 return !!(ed || (!Ext.isDefined(ed) && c.editor));
3959 * Returns the editor defined for the cell/column.
3960 * @param {Number} colIndex The column index
3961 * @param {Number} rowIndex The row index
3962 * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap
3963 * the {@link Ext.form.Field Field} used to edit the cell.
3965 getCellEditor : function(colIndex, rowIndex){
3966 return this.config[colIndex].getCellEditor(rowIndex);
3970 * Sets if a column is editable.
3971 * @param {Number} col The column index
3972 * @param {Boolean} editable True if the column is editable
3974 setEditable : function(col, editable){
3975 this.config[col].editable = editable;
3979 * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#hidden hidden}</code>,
3980 * <tt>false</tt> otherwise.
3981 * @param {Number} colIndex The column index
3984 isHidden : function(colIndex){
3985 return !!this.config[colIndex].hidden; // ensure returns boolean
3989 * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#fixed fixed}</code>,
3990 * <tt>false</tt> otherwise.
3991 * @param {Number} colIndex The column index
3994 isFixed : function(colIndex){
3995 return !!this.config[colIndex].fixed;
3999 * Returns true if the column can be resized
4002 isResizable : function(colIndex){
4003 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
4006 * Sets if a column is hidden.
4008 myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
4010 * @param {Number} colIndex The column index
4011 * @param {Boolean} hidden True if the column is hidden
4013 setHidden : function(colIndex, hidden){
4014 var c = this.config[colIndex];
4015 if(c.hidden !== hidden){
4017 this.totalWidth = null;
4018 this.fireEvent("hiddenchange", this, colIndex, hidden);
4023 * Sets the editor for a column and destroys the prior editor.
4024 * @param {Number} col The column index
4025 * @param {Object} editor The editor object
4027 setEditor : function(col, editor){
4028 this.config[col].setEditor(editor);
4032 * Destroys this column model by purging any event listeners, and removing any editors.
4034 destroy : function(){
4036 for(var i = 0, len = this.config.length; i < len; i++){
4042 this.purgeListeners();
4047 Ext.grid.ColumnModel.defaultRenderer = function(value){
4048 if(typeof value == "string" && value.length < 1){
4053 * @class Ext.grid.AbstractSelectionModel
4054 * @extends Ext.util.Observable
4055 * Abstract base class for grid SelectionModels. It provides the interface that should be
4056 * implemented by descendant classes. This class should not be directly instantiated.
4059 Ext.grid.AbstractSelectionModel = Ext.extend(Ext.util.Observable, {
4061 * The GridPanel for which this SelectionModel is handling selection. Read-only.
4066 constructor : function(){
4067 this.locked = false;
4068 Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);
4071 /** @ignore Called by the grid automatically. Do not call directly. */
4072 init : function(grid){
4074 if(this.lockOnInit){
4075 delete this.lockOnInit;
4076 this.locked = false;
4083 * Locks the selections.
4088 // If the grid has been set, then the view is already initialized.
4093 beforerefresh: this.sortUnLock,
4094 refresh: this.sortLock
4097 this.lockOnInit = true;
4102 // set the lock states before and after a view refresh
4103 sortLock : function() {
4107 // set the lock states before and after a view refresh
4108 sortUnLock : function() {
4109 this.locked = false;
4113 * Unlocks the selections.
4115 unlock : function(){
4117 this.locked = false;
4121 // If the grid has been set, then the view is already initialized.
4124 gv.un('beforerefresh', this.sortUnLock, this);
4125 gv.un('refresh', this.sortLock, this);
4127 delete this.lockOnInit;
4133 * Returns true if the selections are locked.
4136 isLocked : function(){
4140 destroy: function(){
4142 this.purgeListeners();
4145 * @class Ext.grid.RowSelectionModel
4146 * @extends Ext.grid.AbstractSelectionModel
4147 * The default SelectionModel used by {@link Ext.grid.GridPanel}.
4148 * It supports multiple selections and keyboard selection/navigation. The objects stored
4149 * as selections and returned by {@link #getSelected}, and {@link #getSelections} are
4150 * the {@link Ext.data.Record Record}s which provide the data for the selected rows.
4152 * @param {Object} config
4154 Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
4156 * @cfg {Boolean} singleSelect
4157 * <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
4158 * allowing multiple selections)
4160 singleSelect : false,
4162 constructor : function(config){
4163 Ext.apply(this, config);
4164 this.selections = new Ext.util.MixedCollection(false, function(o){
4169 this.lastActive = false;
4173 * @event selectionchange
4174 * Fires when the selection changes
4175 * @param {SelectionModel} this
4179 * @event beforerowselect
4180 * Fires before a row is selected, return false to cancel the selection.
4181 * @param {SelectionModel} this
4182 * @param {Number} rowIndex The index to be selected
4183 * @param {Boolean} keepExisting False if other selections will be cleared
4184 * @param {Record} record The record to be selected
4189 * Fires when a row is selected.
4190 * @param {SelectionModel} this
4191 * @param {Number} rowIndex The selected index
4192 * @param {Ext.data.Record} r The selected record
4196 * @event rowdeselect
4197 * Fires when a row is deselected. To prevent deselection
4198 * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
4199 * @param {SelectionModel} this
4200 * @param {Number} rowIndex
4201 * @param {Record} record
4205 Ext.grid.RowSelectionModel.superclass.constructor.call(this);
4209 * @cfg {Boolean} moveEditorOnEnter
4210 * <tt>false</tt> to turn off moving the editor to the next row down when the enter key is pressed
4211 * or the next row up when shift + enter keys are pressed.
4214 initEvents : function(){
4216 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
4217 this.grid.on('rowmousedown', this.handleMouseDown, this);
4220 this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
4222 if(!e.shiftKey || this.singleSelect){
4223 this.selectPrevious(false);
4224 }else if(this.last !== false && this.lastActive !== false){
4225 var last = this.last;
4226 this.selectRange(this.last, this.lastActive-1);
4227 this.grid.getView().focusRow(this.lastActive);
4232 this.selectFirstRow();
4235 'down' : function(e){
4236 if(!e.shiftKey || this.singleSelect){
4237 this.selectNext(false);
4238 }else if(this.last !== false && this.lastActive !== false){
4239 var last = this.last;
4240 this.selectRange(this.last, this.lastActive+1);
4241 this.grid.getView().focusRow(this.lastActive);
4246 this.selectFirstRow();
4252 this.grid.getView().on({
4254 refresh: this.onRefresh,
4255 rowupdated: this.onRowUpdated,
4256 rowremoved: this.onRemove
4261 onRefresh : function(){
4262 var ds = this.grid.store, index;
4263 var s = this.getSelections();
4264 this.clearSelections(true);
4265 for(var i = 0, len = s.length; i < len; i++){
4267 if((index = ds.indexOfId(r.id)) != -1){
4268 this.selectRow(index, true);
4271 if(s.length != this.selections.getCount()){
4272 this.fireEvent('selectionchange', this);
4277 onRemove : function(v, index, r){
4278 if(this.selections.remove(r) !== false){
4279 this.fireEvent('selectionchange', this);
4284 onRowUpdated : function(v, index, r){
4285 if(this.isSelected(r)){
4286 v.onRowSelect(index);
4292 * @param {Array} records The records to select
4293 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4295 selectRecords : function(records, keepExisting){
4297 this.clearSelections();
4299 var ds = this.grid.store;
4300 for(var i = 0, len = records.length; i < len; i++){
4301 this.selectRow(ds.indexOf(records[i]), true);
4306 * Gets the number of selected rows.
4309 getCount : function(){
4310 return this.selections.length;
4314 * Selects the first row in the grid.
4316 selectFirstRow : function(){
4321 * Select the last row.
4322 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4324 selectLastRow : function(keepExisting){
4325 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
4329 * Selects the row immediately following the last selected row.
4330 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4331 * @return {Boolean} <tt>true</tt> if there is a next row, else <tt>false</tt>
4333 selectNext : function(keepExisting){
4335 this.selectRow(this.last+1, keepExisting);
4336 this.grid.getView().focusRow(this.last);
4343 * Selects the row that precedes the last selected row.
4344 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4345 * @return {Boolean} <tt>true</tt> if there is a previous row, else <tt>false</tt>
4347 selectPrevious : function(keepExisting){
4348 if(this.hasPrevious()){
4349 this.selectRow(this.last-1, keepExisting);
4350 this.grid.getView().focusRow(this.last);
4357 * Returns true if there is a next record to select
4360 hasNext : function(){
4361 return this.last !== false && (this.last+1) < this.grid.store.getCount();
4365 * Returns true if there is a previous record to select
4368 hasPrevious : function(){
4374 * Returns the selected records
4375 * @return {Array} Array of selected records
4377 getSelections : function(){
4378 return [].concat(this.selections.items);
4382 * Returns the first selected record.
4385 getSelected : function(){
4386 return this.selections.itemAt(0);
4390 * Calls the passed function with each selection. If the function returns
4391 * <tt>false</tt>, iteration is stopped and this function returns
4392 * <tt>false</tt>. Otherwise it returns <tt>true</tt>.
4393 * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}.
4394 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel.
4395 * @return {Boolean} true if all selections were iterated
4397 each : function(fn, scope){
4398 var s = this.getSelections();
4399 for(var i = 0, len = s.length; i < len; i++){
4400 if(fn.call(scope || this, s[i], i) === false){
4408 * Clears all selections if the selection model
4409 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4410 * @param {Boolean} fast (optional) <tt>true</tt> to bypass the
4411 * conditional checks and events described in {@link #deselectRow}.
4413 clearSelections : function(fast){
4414 if(this.isLocked()){
4418 var ds = this.grid.store;
4419 var s = this.selections;
4421 this.deselectRow(ds.indexOfId(r.id));
4425 this.selections.clear();
4432 * Selects all rows if the selection model
4433 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4435 selectAll : function(){
4436 if(this.isLocked()){
4439 this.selections.clear();
4440 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
4441 this.selectRow(i, true);
4446 * Returns <tt>true</tt> if there is a selection.
4449 hasSelection : function(){
4450 return this.selections.length > 0;
4454 * Returns <tt>true</tt> if the specified row is selected.
4455 * @param {Number/Record} index The record or index of the record to check
4458 isSelected : function(index){
4459 var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
4460 return (r && this.selections.key(r.id) ? true : false);
4464 * Returns <tt>true</tt> if the specified record id is selected.
4465 * @param {String} id The id of record to check
4468 isIdSelected : function(id){
4469 return (this.selections.key(id) ? true : false);
4473 handleMouseDown : function(g, rowIndex, e){
4474 if(e.button !== 0 || this.isLocked()){
4477 var view = this.grid.getView();
4478 if(e.shiftKey && !this.singleSelect && this.last !== false){
4479 var last = this.last;
4480 this.selectRange(last, rowIndex, e.ctrlKey);
4481 this.last = last; // reset the last
4482 view.focusRow(rowIndex);
4484 var isSelected = this.isSelected(rowIndex);
4485 if(e.ctrlKey && isSelected){
4486 this.deselectRow(rowIndex);
4487 }else if(!isSelected || this.getCount() > 1){
4488 this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
4489 view.focusRow(rowIndex);
4495 * Selects multiple rows.
4496 * @param {Array} rows Array of the indexes of the row to select
4497 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep
4498 * existing selections (defaults to <tt>false</tt>)
4500 selectRows : function(rows, keepExisting){
4502 this.clearSelections();
4504 for(var i = 0, len = rows.length; i < len; i++){
4505 this.selectRow(rows[i], true);
4510 * Selects a range of rows if the selection model
4511 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4512 * All rows in between startRow and endRow are also selected.
4513 * @param {Number} startRow The index of the first row in the range
4514 * @param {Number} endRow The index of the last row in the range
4515 * @param {Boolean} keepExisting (optional) True to retain existing selections
4517 selectRange : function(startRow, endRow, keepExisting){
4519 if(this.isLocked()){
4523 this.clearSelections();
4525 if(startRow <= endRow){
4526 for(i = startRow; i <= endRow; i++){
4527 this.selectRow(i, true);
4530 for(i = startRow; i >= endRow; i--){
4531 this.selectRow(i, true);
4537 * Deselects a range of rows if the selection model
4538 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4539 * All rows in between startRow and endRow are also deselected.
4540 * @param {Number} startRow The index of the first row in the range
4541 * @param {Number} endRow The index of the last row in the range
4543 deselectRange : function(startRow, endRow, preventViewNotify){
4544 if(this.isLocked()){
4547 for(var i = startRow; i <= endRow; i++){
4548 this.deselectRow(i, preventViewNotify);
4553 * Selects a row. Before selecting a row, checks if the selection model
4554 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked} and fires the
4555 * {@link #beforerowselect} event. If these checks are satisfied the row
4556 * will be selected and followed up by firing the {@link #rowselect} and
4557 * {@link #selectionchange} events.
4558 * @param {Number} row The index of the row to select
4559 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4560 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
4561 * prevent notifying the view (disables updating the selected appearance)
4563 selectRow : function(index, keepExisting, preventViewNotify){
4564 if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){
4567 var r = this.grid.store.getAt(index);
4568 if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
4569 if(!keepExisting || this.singleSelect){
4570 this.clearSelections();
4572 this.selections.add(r);
4573 this.last = this.lastActive = index;
4574 if(!preventViewNotify){
4575 this.grid.getView().onRowSelect(index);
4577 this.fireEvent('rowselect', this, index, r);
4578 this.fireEvent('selectionchange', this);
4583 * Deselects a row. Before deselecting a row, checks if the selection model
4584 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked}.
4585 * If this check is satisfied the row will be deselected and followed up by
4586 * firing the {@link #rowdeselect} and {@link #selectionchange} events.
4587 * @param {Number} row The index of the row to deselect
4588 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
4589 * prevent notifying the view (disables updating the selected appearance)
4591 deselectRow : function(index, preventViewNotify){
4592 if(this.isLocked()){
4595 if(this.last == index){
4598 if(this.lastActive == index){
4599 this.lastActive = false;
4601 var r = this.grid.store.getAt(index);
4603 this.selections.remove(r);
4604 if(!preventViewNotify){
4605 this.grid.getView().onRowDeselect(index);
4607 this.fireEvent('rowdeselect', this, index, r);
4608 this.fireEvent('selectionchange', this);
4613 restoreLast : function(){
4615 this.last = this._last;
4620 acceptsNav : function(row, col, cm){
4621 return !cm.isHidden(col) && cm.isCellEditable(col, row);
4625 onEditorKey : function(field, e){
4630 ed = g.activeEditor,
4632 var shift = e.shiftKey;
4637 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
4639 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
4641 }else if(k == e.ENTER){
4642 if(this.moveEditorOnEnter !== false){
4644 newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
4646 newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
4655 this.selectRow(r); // *** highlight newly-selected cell and update selection
4658 if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
4659 ae = g.activeEditor;
4660 if(ae && ae.field.triggerBlur){
4661 // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
4662 ae.field.triggerBlur();
4665 g.startEditing(r, c);
4669 destroy : function(){
4671 this.rowNav.disable();
4674 Ext.grid.RowSelectionModel.superclass.destroy.call(this);
4677 * @class Ext.grid.Column
4678 * <p>This class encapsulates column configuration data to be used in the initialization of a
4679 * {@link Ext.grid.ColumnModel ColumnModel}.</p>
4680 * <p>While subclasses are provided to render data in different ways, this class renders a passed
4681 * data field unchanged and is usually used for textual columns.</p>
4683 Ext.grid.Column = Ext.extend(Object, {
4685 * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured
4686 * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column.
4687 * The initial configuration may be dynamically altered using
4688 * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}.
4691 * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial
4692 * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all
4693 * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be
4694 * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre>
4695 * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre>
4696 * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre>
4697 * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this
4698 * unique identifier.
4701 * @cfg {String} header Optional. The header text to be used as innerHTML
4702 * (html tags are accepted) to display in the Grid view. <b>Note</b>: to
4703 * have a clickable header with no text displayed use <tt>' '</tt>.
4706 * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
4707 * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>,
4708 * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the
4709 * group option in the header menu for the column. See also <code>{@link #groupName}</code>.
4712 * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
4713 * may be used to specify the text with which to prefix the group field value in the group header line.
4714 * See also {@link #groupRenderer} and
4715 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}.
4718 * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
4719 * may be used to specify the function used to format the grouping field value for display in the group
4720 * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured
4721 * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified
4722 * the new value of the group field will be used.</p>
4723 * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be
4724 * passed the following parameters:
4725 * <div class="mdetail-params"><ul>
4726 * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li>
4727 * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li>
4728 * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data
4729 * for the row which caused group change.</p></li>
4730 * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>
4731 * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li>
4732 * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
4734 * <p>The function should return a string value.</p>
4737 * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
4738 * may be used to specify the text to display when there is an empty group value. Defaults to the
4739 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}.
4742 * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
4743 * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
4744 * which to draw the column's value.</p>
4747 * @cfg {Number} width
4748 * Optional. The initial width in pixels of the column.
4749 * The width of each column can also be affected if any of the following are configured:
4750 * <div class="mdetail-params"><ul>
4751 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li>
4752 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt>
4753 * <div class="sub-desc">
4754 * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be
4755 * re-proportioned (based on the relative initial widths) to fill the width of the grid so
4756 * that no horizontal scrollbar is shown.</p>
4758 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li>
4759 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li>
4760 * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side
4761 * is reserved for the vertical scrollbar. The
4762 * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt>
4763 * can be modified to reduce or eliminate the reserved offset.</p>
4766 * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column.
4767 * Defaults to the value of the <code>{@link Ext.grid.ColumnModel#defaultSortable}</code> property.
4768 * Whether local/remote sorting is used is specified in <code>{@link Ext.data.Store#remoteSort}</code>.
4771 * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>.
4774 * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>.
4777 * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>.
4780 * @cfg {Boolean} hidden
4781 * Optional. <tt>true</tt> to initially hide this column. Defaults to <tt>false</tt>.
4782 * A hidden column {@link Ext.grid.GridPanel#enableColumnHide may be shown via the header row menu}.
4783 * If a column is never to be shown, simply do not include this column in the Column Model at all.
4786 * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips
4787 * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the
4788 * header's HTML title attribute. Defaults to ''.
4791 * @cfg {Mixed} renderer
4792 * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p>
4793 * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value,
4794 * appearance, etc.) before it is rendered). This may be specified in either of three ways:
4795 * <div class="mdetail-params"><ul>
4796 * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li>
4797 * <li>A string which references a property name of the {@link Ext.util.Format} class which
4798 * provides a renderer function.</li>
4799 * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt>
4800 * reference) e.g.:<pre style="margin-left:1.2em"><code>
4802 fn: this.gridRenderer,
4805 </code></pre></li></ul></div>
4806 * If not specified, the default renderer uses the raw data value.</p>
4807 * <p>For information about the renderer function (passed parameters, etc.), see
4808 * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code>
4809 var companyColumn = {
4810 header: 'Company Name',
4811 dataIndex: 'company',
4812 renderer: function(value, metaData, record, rowIndex, colIndex, store) {
4813 // provide the logic depending on business rules
4814 // name of your own choosing to manipulate the cell depending upon
4815 // the data in the underlying Record object.
4816 if (value == 'whatever') {
4817 //metaData.css : String : A CSS class name to add to the TD element of the cell.
4818 //metaData.attr : String : An html attribute definition string to apply to
4819 // the data container element within the table
4820 // cell (e.g. 'style="color:red;"').
4821 metaData.css = 'name-of-css-class-you-will-define';
4827 * See also {@link #scope}.
4830 * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass
4831 * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily
4832 * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are:
4833 * <div class="mdetail-params"><ul>
4834 * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li>
4835 * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li>
4836 * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li>
4837 * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li>
4838 * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li>
4840 * <p>Configuration properties for the specified <code>xtype</code> may be specified with
4841 * the Column configuration properties, for example:</p>
4843 var grid = new Ext.grid.GridPanel({
4846 header: 'Last Updated',
4847 dataIndex: 'lastChange',
4850 //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
4851 xtype: 'datecolumn', // use xtype instead of renderer
4852 format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn}
4860 * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the
4861 * renderer. Defaults to the Column configuration object.
4864 * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined.
4867 * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column
4868 * (excluding headers). Defaults to undefined.
4871 * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column
4872 * (defaults to true). To disallow column hiding globally for all columns in the grid, use
4873 * {@link Ext.grid.GridPanel#enableColumnHide} instead.
4876 * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column
4877 * if editing is supported by the grid. See <tt>{@link #editable}</tt> also.
4882 * @cfg {Boolean} isColumn
4883 * Used by ColumnModel setConfig method to avoid reprocessing a Column
4884 * if <code>isColumn</code> is not set ColumnModel will recreate a new Ext.grid.Column
4889 constructor : function(config){
4890 Ext.apply(this, config);
4892 if(Ext.isString(this.renderer)){
4893 this.renderer = Ext.util.Format[this.renderer];
4894 }else if(Ext.isObject(this.renderer)){
4895 this.scope = this.renderer.scope;
4896 this.renderer = this.renderer.fn;
4902 var ed = this.editor;
4908 * Optional. A function which returns displayable data when passed the following parameters:
4909 * <div class="mdetail-params"><ul>
4910 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
4911 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
4912 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
4913 * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container
4914 * element <i>within</i> the table cell (e.g. 'style="color:red;"').</p></li></ul></p></li>
4915 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was
4916 * extracted.</p></li>
4917 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
4918 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
4919 * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record
4920 * was extracted.</p></li>
4922 * @property renderer
4925 renderer : function(value){
4926 if(Ext.isString(value) && value.length < 1){
4933 getEditor: function(rowIndex){
4934 return this.editable !== false ? this.editor : null;
4938 * Sets a new editor for this column.
4939 * @param {Ext.Editor/Ext.form.Field} editor The editor to set
4941 setEditor : function(editor){
4942 var ed = this.editor;
4945 ed.gridEditor.destroy();
4946 delete ed.gridEditor;
4953 //not an instance, create it
4954 if(!editor.isXType){
4955 editor = Ext.create(editor, 'textfield');
4957 this.editor = editor;
4962 * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}
4963 * used to edit the cell.
4964 * @param {Number} rowIndex The row index
4965 * @return {Ext.Editor}
4967 getCellEditor: function(rowIndex){
4968 var ed = this.getEditor(rowIndex);
4972 ed.gridEditor = new Ext.grid.GridEditor(ed);
4982 * @class Ext.grid.BooleanColumn
4983 * @extends Ext.grid.Column
4984 * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.Column#xtype xtype}
4985 * config option of {@link Ext.grid.Column} for more details.</p>
4987 Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {
4989 * @cfg {String} trueText
4990 * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).
4994 * @cfg {String} falseText
4995 * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to
4996 * <tt>'false'</tt>).
5000 * @cfg {String} undefinedText
5001 * The string returned by the renderer when the column value is undefined (defaults to <tt>' '</tt>).
5003 undefinedText: ' ',
5005 constructor: function(cfg){
5006 Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);
5007 var t = this.trueText, f = this.falseText, u = this.undefinedText;
5008 this.renderer = function(v){
5009 if(v === undefined){
5012 if(!v || v === 'false'){
5021 * @class Ext.grid.NumberColumn
5022 * @extends Ext.grid.Column
5023 * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the
5024 * {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more details.</p>
5026 Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {
5028 * @cfg {String} format
5029 * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
5030 * (defaults to <tt>'0,000.00'</tt>).
5032 format : '0,000.00',
5033 constructor: function(cfg){
5034 Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);
5035 this.renderer = Ext.util.Format.numberRenderer(this.format);
5040 * @class Ext.grid.DateColumn
5041 * @extends Ext.grid.Column
5042 * <p>A Column definition class which renders a passed date according to the default locale, or a configured
5043 * {@link #format}. See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column}
5044 * for more details.</p>
5046 Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {
5048 * @cfg {String} format
5049 * A formatting string as used by {@link Date#format} to format a Date for this Column
5050 * (defaults to <tt>'m/d/Y'</tt>).
5053 constructor: function(cfg){
5054 Ext.grid.DateColumn.superclass.constructor.call(this, cfg);
5055 this.renderer = Ext.util.Format.dateRenderer(this.format);
5060 * @class Ext.grid.TemplateColumn
5061 * @extends Ext.grid.Column
5062 * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s
5063 * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}.
5064 * See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more
5067 Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
5069 * @cfg {String/XTemplate} tpl
5070 * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a
5071 * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value.
5073 constructor: function(cfg){
5074 Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);
5075 var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl);
5076 this.renderer = function(value, p, r){
5077 return tpl.apply(r.data);
5086 * @member Ext.grid.Column
5088 * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced
5089 * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p>
5090 * <p>This contains the following properties</p><div class="mdesc-details"><ul>
5091 * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li>
5092 * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li>
5093 * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li>
5094 * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li>
5095 * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li>
5098 Ext.grid.Column.types = {
5099 gridcolumn : Ext.grid.Column,
5100 booleancolumn: Ext.grid.BooleanColumn,
5101 numbercolumn: Ext.grid.NumberColumn,
5102 datecolumn: Ext.grid.DateColumn,
5103 templatecolumn: Ext.grid.TemplateColumn
5105 * @class Ext.grid.RowNumberer
5106 * This is a utility class that can be passed into a {@link Ext.grid.ColumnModel} as a column config that provides
5107 * an automatic row numbering column.
5110 // This is a typical column config with the first column providing row numbers
5111 var colModel = new Ext.grid.ColumnModel([
5112 new Ext.grid.RowNumberer(),
5113 {header: "Name", width: 80, sortable: true},
5114 {header: "Code", width: 50, sortable: true},
5115 {header: "Description", width: 200, sortable: true}
5119 * @param {Object} config The configuration options
5121 Ext.grid.RowNumberer = Ext.extend(Object, {
5123 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
5124 * number column (defaults to '').
5128 * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
5132 * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
5137 constructor : function(config){
5138 Ext.apply(this, config);
5140 this.renderer = this.renderer.createDelegate(this);
5153 renderer : function(v, p, record, rowIndex){
5155 p.cellAttr = 'rowspan="'+this.rowspan+'"';
5160 * @class Ext.grid.CheckboxSelectionModel
5161 * @extends Ext.grid.RowSelectionModel
5162 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
5164 * @param {Object} config The configuration options
5166 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
5169 * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
5170 * checkbox column (defaults to <tt>false</tt>).
5173 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
5174 * checkbox column. Defaults to:<pre><code>
5175 * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
5177 * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
5178 * and provides support for automatic check all/none behavior on header click. This string
5179 * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
5180 * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
5181 * <tt>'x-grid3-hd-checker'</tt> class is supplied.
5183 header : '<div class="x-grid3-hd-checker"> </div>',
5185 * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
5189 * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
5195 menuDisabled : true,
5201 constructor : function(){
5202 Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
5205 this.handleMouseDown = Ext.emptyFn;
5210 initEvents : function(){
5211 Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
5212 this.grid.on('render', function(){
5213 var view = this.grid.getView();
5214 view.mainBody.on('mousedown', this.onMouseDown, this);
5215 Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
5220 // If handleMouseDown was called from another event (enableDragDrop), set a flag so
5221 // onMouseDown does not process it a second time
5222 handleMouseDown : function() {
5223 Ext.grid.CheckboxSelectionModel.superclass.handleMouseDown.apply(this, arguments);
5224 this.mouseHandled = true;
5228 onMouseDown : function(e, t){
5229 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
5231 var row = e.getTarget('.x-grid3-row');
5233 // mouseHandled flag check for a duplicate selection (handleMouseDown) call
5234 if(!this.mouseHandled && row){
5235 var index = row.rowIndex;
5236 if(this.isSelected(index)){
5237 this.deselectRow(index);
5239 this.selectRow(index, true);
5240 this.grid.getView().focusRow(index);
5244 this.mouseHandled = false;
5248 onHdMouseDown : function(e, t){
5249 if(t.className == 'x-grid3-hd-checker'){
5251 var hd = Ext.fly(t.parentNode);
5252 var isChecked = hd.hasClass('x-grid3-hd-checker-on');
5254 hd.removeClass('x-grid3-hd-checker-on');
5255 this.clearSelections();
5257 hd.addClass('x-grid3-hd-checker-on');
5264 renderer : function(v, p, record){
5265 return '<div class="x-grid3-row-checker"> </div>';