Upgrade to ExtJS 3.3.0 - Released 10/06/2010
[extjs.git] / docs / source / GridView.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.3.0
11  * Copyright(c) 2006-2010 Ext JS, Inc.
12  * licensing@extjs.com
13  * http://www.extjs.com/license
14  */
15 <div id="cls-Ext.grid.GridView"></div>/**
16  * @class Ext.grid.GridView
17  * @extends Ext.util.Observable
18  * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
19  * Methods of this class may be used to access user interface elements to enable
20  * special display effects. Do not change the DOM structure of the user interface.</p>
21  * <p>This class does not provide ways to manipulate the underlying data. The data
22  * model of a Grid is held in an {@link Ext.data.Store}.</p>
23  * @constructor
24  * @param {Object} config
25  */
26 Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
27     <div id="method-Ext.grid.GridView-getRowClass"></div>/**
28      * Override this function to apply custom CSS classes to rows during rendering.  You can also supply custom
29      * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
30      * parameter.  This function should return the CSS class name (or empty string '' for none) that will be added
31      * to the row's wrapping div.  To apply multiple class names, simply return them space-delimited within the string
32      * (e.g., 'my-class another-class'). Example usage:
33     <pre><code>
34 viewConfig: {
35     forceFit: true,
36     showPreview: true, // custom property
37     enableRowBody: true, // required to create a second, full-width row to show expanded Record data
38     getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
39         if(this.showPreview){
40             rp.body = '&lt;p>'+record.data.excerpt+'&lt;/p>';
41             return 'x-grid3-row-expanded';
42         }
43         return 'x-grid3-row-collapsed';
44     }
45 },
46     </code></pre>
47      * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
48      * @param {Number} index The row index.
49      * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
50      * customization of various aspects of a grid row.
51      * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
52      * by this function, and will be used to render a full-width expansion row below each grid row:</p>
53      * <ul>
54      * <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>
55      * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's &lt;tr> element. (defaults to '').</div></li>
56      * </ul>
57      * The following property will be passed in, and may be appended to:
58      * <ul>
59      * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the &lt;table> element which encapsulates
60      * both the standard grid row, and any expansion row.</div></li>
61      * </ul>
62      * @param {Store} store The {@link Ext.data.Store} this grid is bound to
63      * @method getRowClass
64      * @return {String} a CSS class name to add to the row.
65      */
66
67     <div id="cfg-Ext.grid.GridView-enableRowBody"></div>/**
68      * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
69      * that spans beneath the data row.  Use the {@link #getRowClass} method's rowParams config to customize the row body.
70      */
71
72     <div id="cfg-Ext.grid.GridView-emptyText"></div>/**
73      * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
74      * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
75     <pre><code>
76     this.mainBody.update('&lt;div class="x-grid-empty">' + this.emptyText + '&lt;/div>');
77     </code></pre>
78      */
79
80     <div id="cfg-Ext.grid.GridView-headersDisabled"></div>/**
81      * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
82      * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
83      * config to disable the <i>menu</i> for individual columns.  While this config is true the
84      * following will be disabled:<div class="mdetail-params"><ul>
85      * <li>clicking on header to sort</li>
86      * <li>the trigger to reveal the menu.</li>
87      * </ul></div>
88      */
89
90     <div id="prop-Ext.grid.GridView-dragZone"></div>/**
91      * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
92      * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
93      * See {@link Ext.grid.GridDragZone} for details.</p>
94      * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>
95      * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>
96      * <li><i>after</i> the owning GridPanel has been rendered.</li>
97      * </ul></div>
98      * @property dragZone
99      * @type {Ext.grid.GridDragZone}
100      */
101
102     <div id="cfg-Ext.grid.GridView-deferEmptyText"></div>/**
103      * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
104      * first load (defaults to <tt>true</tt>).
105      */
106     deferEmptyText : true,
107
108     <div id="cfg-Ext.grid.GridView-scrollOffset"></div>/**
109      * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
110      * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
111      * calculated.
112      */
113     scrollOffset : undefined,
114
115     <div id="cfg-Ext.grid.GridView-autoFill"></div>/**
116      * @cfg {Boolean} autoFill
117      * Defaults to <tt>false</tt>.  Specify <tt>true</tt> to have the column widths re-proportioned
118      * when the grid is <b>initially rendered</b>.  The
119      * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
120      * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
121      * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
122      * See <tt>{@link #forceFit}</tt> also.
123      */
124     autoFill : false,
125
126     <div id="cfg-Ext.grid.GridView-forceFit"></div>/**
127      * @cfg {Boolean} forceFit
128      * Defaults to <tt>false</tt>.  Specify <tt>true</tt> to have the column widths re-proportioned
129      * at <b>all times</b>.  The {@link Ext.grid.Column#width initially configured width}</tt> of each
130      * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are
131      * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized
132      * to fit the grid width. See <tt>{@link #autoFill}</tt> also.
133      */
134     forceFit : false,
135
136     <div id="cfg-Ext.grid.GridView-sortClasses"></div>/**
137      * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
138      */
139     sortClasses : ['sort-asc', 'sort-desc'],
140
141     <div id="cfg-Ext.grid.GridView-sortAscText"></div>/**
142      * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
143      */
144     sortAscText : 'Sort Ascending',
145
146     <div id="cfg-Ext.grid.GridView-sortDescText"></div>/**
147      * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
148      */
149     sortDescText : 'Sort Descending',
150
151     <div id="cfg-Ext.grid.GridView-columnsText"></div>/**
152      * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>)
153      */
154     columnsText : 'Columns',
155
156     <div id="cfg-Ext.grid.GridView-selectedRowClass"></div>/**
157      * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An
158      * example overriding the default styling:
159     <pre><code>
160     .x-grid3-row-selected {background-color: yellow;}
161     </code></pre>
162      * Note that this only controls the row, and will not do anything for the text inside it.  To style inner
163      * facets (like text) use something like:
164     <pre><code>
165     .x-grid3-row-selected .x-grid3-cell-inner {
166         color: #FFCC00;
167     }
168     </code></pre>
169      * @type String
170      */
171     selectedRowClass : 'x-grid3-row-selected',
172
173     // private
174     borderWidth : 2,
175     tdClass : 'x-grid3-cell',
176     hdCls : 'x-grid3-hd',
177     
178     
179     <div id="cfg-Ext.grid.GridView-markDirty"></div>/**
180      * @cfg {Boolean} markDirty True to show the dirty cell indicator when a cell has been modified. Defaults to <tt>true</tt>.
181      */
182     markDirty : true,
183
184     <div id="cfg-Ext.grid.GridView-cellSelectorDepth"></div>/**
185      * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
186      */
187     cellSelectorDepth : 4,
188     
189     <div id="cfg-Ext.grid.GridView-rowSelectorDepth"></div>/**
190      * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
191      */
192     rowSelectorDepth : 10,
193
194     <div id="cfg-Ext.grid.GridView-rowBodySelectorDepth"></div>/**
195      * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
196      */
197     rowBodySelectorDepth : 10,
198
199     <div id="cfg-Ext.grid.GridView-cellSelector"></div>/**
200      * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
201      */
202     cellSelector : 'td.x-grid3-cell',
203     
204     <div id="cfg-Ext.grid.GridView-rowSelector"></div>/**
205      * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
206      */
207     rowSelector : 'div.x-grid3-row',
208
209     <div id="cfg-Ext.grid.GridView-rowBodySelector"></div>/**
210      * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
211      */
212     rowBodySelector : 'div.x-grid3-row-body',
213
214     // private
215     firstRowCls: 'x-grid3-row-first',
216     lastRowCls: 'x-grid3-row-last',
217     rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
218     
219     <div id="cfg-Ext.grid.GridView-headerMenuOpenCls"></div>/**
220      * @cfg {String} headerMenuOpenCls The CSS class to add to the header cell when its menu is visible. Defaults to 'x-grid3-hd-menu-open'
221      */
222     headerMenuOpenCls: 'x-grid3-hd-menu-open',
223     
224     <div id="cfg-Ext.grid.GridView-rowOverCls"></div>/**
225      * @cfg {String} rowOverCls The CSS class added to each row when it is hovered over. Defaults to 'x-grid3-row-over'
226      */
227     rowOverCls: 'x-grid3-row-over',
228
229     constructor : function(config) {
230         Ext.apply(this, config);
231         
232         // These events are only used internally by the grid components
233         this.addEvents(
234             <div id="event-Ext.grid.GridView-beforerowremoved"></div>/**
235              * @event beforerowremoved
236              * Internal UI Event. Fired before a row is removed.
237              * @param {Ext.grid.GridView} view
238              * @param {Number} rowIndex The index of the row to be removed.
239              * @param {Ext.data.Record} record The Record to be removed
240              */
241             'beforerowremoved',
242             
243             <div id="event-Ext.grid.GridView-beforerowsinserted"></div>/**
244              * @event beforerowsinserted
245              * Internal UI Event. Fired before rows are inserted.
246              * @param {Ext.grid.GridView} view
247              * @param {Number} firstRow The index of the first row to be inserted.
248              * @param {Number} lastRow The index of the last row to be inserted.
249              */
250             'beforerowsinserted',
251             
252             <div id="event-Ext.grid.GridView-beforerefresh"></div>/**
253              * @event beforerefresh
254              * Internal UI Event. Fired before the view is refreshed.
255              * @param {Ext.grid.GridView} view
256              */
257             'beforerefresh',
258             
259             <div id="event-Ext.grid.GridView-rowremoved"></div>/**
260              * @event rowremoved
261              * Internal UI Event. Fired after a row is removed.
262              * @param {Ext.grid.GridView} view
263              * @param {Number} rowIndex The index of the row that was removed.
264              * @param {Ext.data.Record} record The Record that was removed
265              */
266             'rowremoved',
267             
268             <div id="event-Ext.grid.GridView-rowsinserted"></div>/**
269              * @event rowsinserted
270              * Internal UI Event. Fired after rows are inserted.
271              * @param {Ext.grid.GridView} view
272              * @param {Number} firstRow The index of the first inserted.
273              * @param {Number} lastRow The index of the last row inserted.
274              */
275             'rowsinserted',
276             
277             <div id="event-Ext.grid.GridView-rowupdated"></div>/**
278              * @event rowupdated
279              * Internal UI Event. Fired after a row has been updated.
280              * @param {Ext.grid.GridView} view
281              * @param {Number} firstRow The index of the row updated.
282              * @param {Ext.data.record} record The Record backing the row updated.
283              */
284             'rowupdated',
285             
286             <div id="event-Ext.grid.GridView-refresh"></div>/**
287              * @event refresh
288              * Internal UI Event. Fired after the GridView's body has been refreshed.
289              * @param {Ext.grid.GridView} view
290              */
291             'refresh'
292         );
293         
294         Ext.grid.GridView.superclass.constructor.call(this);
295     },
296
297     /* -------------------------------- UI Specific ----------------------------- */
298     
299     <div id="prop-Ext.grid.GridView-Ext.Template"></div>/**
300      * The master template to use when rendering the GridView. Has a default template
301      * @property Ext.Template
302      * @type masterTpl
303      */
304     masterTpl: new Ext.Template(
305         '<div class="x-grid3" hidefocus="true">',
306             '<div class="x-grid3-viewport">',
307                 '<div class="x-grid3-header">',
308                     '<div class="x-grid3-header-inner">',
309                         '<div class="x-grid3-header-offset" style="{ostyle}">{header}</div>',
310                     '</div>',
311                     '<div class="x-clear"></div>',
312                 '</div>',
313                 '<div class="x-grid3-scroller">',
314                     '<div class="x-grid3-body" style="{bstyle}">{body}</div>',
315                     '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
316                 '</div>',
317             '</div>',
318             '<div class="x-grid3-resize-marker">&#160;</div>',
319             '<div class="x-grid3-resize-proxy">&#160;</div>',
320         '</div>'
321     ),
322     
323     <div id="prop-Ext.grid.GridView-headerTpl"></div>/**
324      * The template to use when rendering headers. Has a default template
325      * @property headerTpl
326      * @type Ext.Template
327      */
328     headerTpl: new Ext.Template(
329         '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
330             '<thead>',
331                 '<tr class="x-grid3-hd-row">{cells}</tr>',
332             '</thead>',
333         '</table>'
334     ),
335     
336     <div id="prop-Ext.grid.GridView-bodyTpl"></div>/**
337      * The template to use when rendering the body. Has a default template
338      * @property bodyTpl
339      * @type Ext.Template
340      */
341     bodyTpl: new Ext.Template('{rows}'),
342     
343     <div id="prop-Ext.grid.GridView-cellTpl"></div>/**
344      * The template to use to render each cell. Has a default template
345      * @property cellTpl
346      * @type Ext.Template
347      */
348     cellTpl: new Ext.Template(
349         '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
350             '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
351         '</td>'
352     ),
353     
354     /**
355      * @private
356      * Provides default templates if they are not given for this particular instance. Most of the templates are defined on
357      * the prototype, the ones defined inside this function are done so because they are based on Grid or GridView configuration
358      */
359     initTemplates : function() {
360         var templates = this.templates || {},
361             template, name,
362             
363             headerCellTpl = new Ext.Template(
364                 '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
365                     '<div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', 
366                         this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
367                         '{value}',
368                         '<img alt="" class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
369                     '</div>',
370                 '</td>'
371             ),
372         
373             rowBodyText = [
374                 '<tr class="x-grid3-row-body-tr" style="{bodyStyle}">',
375                     '<td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on">',
376                         '<div class="x-grid3-row-body">{body}</div>',
377                     '</td>',
378                 '</tr>'
379             ].join(""),
380         
381             innerText = [
382                 '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
383                      '<tbody>',
384                         '<tr>{cells}</tr>',
385                         this.enableRowBody ? rowBodyText : '',
386                      '</tbody>',
387                 '</table>'
388             ].join("");
389         
390         Ext.applyIf(templates, {
391             hcell   : headerCellTpl,
392             cell    : this.cellTpl,
393             body    : this.bodyTpl,
394             header  : this.headerTpl,
395             master  : this.masterTpl,
396             row     : new Ext.Template('<div class="x-grid3-row {alt}" style="{tstyle}">' + innerText + '</div>'),
397             rowInner: new Ext.Template(innerText)
398         });
399
400         for (name in templates) {
401             template = templates[name];
402             
403             if (template && Ext.isFunction(template.compile) && !template.compiled) {
404                 template.disableFormats = true;
405                 template.compile();
406             }
407         }
408
409         this.templates = templates;
410         this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
411     },
412
413     /**
414      * @private
415      * Each GridView has its own private flyweight, accessed through this method
416      */
417     fly : function(el) {
418         if (!this._flyweight) {
419             this._flyweight = new Ext.Element.Flyweight(document.body);
420         }
421         this._flyweight.dom = el;
422         return this._flyweight;
423     },
424
425     // private
426     getEditorParent : function() {
427         return this.scroller.dom;
428     },
429
430     /**
431      * @private
432      * Finds and stores references to important elements
433      */
434     initElements : function() {
435         var Element  = Ext.Element,
436             el       = Ext.get(this.grid.getGridEl().dom.firstChild),
437             mainWrap = new Element(el.child('div.x-grid3-viewport')),
438             mainHd   = new Element(mainWrap.child('div.x-grid3-header')),
439             scroller = new Element(mainWrap.child('div.x-grid3-scroller'));
440         
441         if (this.grid.hideHeaders) {
442             mainHd.setDisplayed(false);
443         }
444         
445         if (this.forceFit) {
446             scroller.setStyle('overflow-x', 'hidden');
447         }
448         
449         <div id="prop-Ext.grid.GridView-mainBody"></div>/**
450          * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
451          * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
452          * @type Ext.Element
453          * @property mainBody
454          */
455         
456         Ext.apply(this, {
457             el      : el,
458             mainWrap: mainWrap,
459             scroller: scroller,
460             mainHd  : mainHd,
461             innerHd : mainHd.child('div.x-grid3-header-inner').dom,
462             mainBody: new Element(Element.fly(scroller).child('div.x-grid3-body')),
463             focusEl : new Element(Element.fly(scroller).child('a')),
464             
465             resizeMarker: new Element(el.child('div.x-grid3-resize-marker')),
466             resizeProxy : new Element(el.child('div.x-grid3-resize-proxy'))
467         });
468         
469         this.focusEl.swallowEvent('click', true);
470     },
471
472     // private
473     getRows : function() {
474         return this.hasRows() ? this.mainBody.dom.childNodes : [];
475     },
476
477     // finder methods, used with delegation
478
479     // private
480     findCell : function(el) {
481         if (!el) {
482             return false;
483         }
484         return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
485     },
486
487     <div id="method-Ext.grid.GridView-findCellIndex"></div>/**
488      * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
489      * See also {@link #findRowIndex}
490      * @param {HTMLElement} el The target element
491      * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
492      */
493     findCellIndex : function(el, requiredCls) {
494         var cell = this.findCell(el),
495             hasCls;
496         
497         if (cell) {
498             hasCls = this.fly(cell).hasClass(requiredCls);
499             if (!requiredCls || hasCls) {
500                 return this.getCellIndex(cell);
501             }
502         }
503         return false;
504     },
505
506     // private
507     getCellIndex : function(el) {
508         if (el) {
509             var match = el.className.match(this.colRe);
510             
511             if (match && match[1]) {
512                 return this.cm.getIndexById(match[1]);
513             }
514         }
515         return false;
516     },
517
518     // private
519     findHeaderCell : function(el) {
520         var cell = this.findCell(el);
521         return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
522     },
523
524     // private
525     findHeaderIndex : function(el){
526         return this.findCellIndex(el, this.hdCls);
527     },
528
529     <div id="method-Ext.grid.GridView-findRow"></div>/**
530      * Return the HtmlElement representing the grid row which contains the passed element.
531      * @param {HTMLElement} el The target HTMLElement
532      * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
533      */
534     findRow : function(el) {
535         if (!el) {
536             return false;
537         }
538         return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
539     },
540
541     <div id="method-Ext.grid.GridView-findRowIndex"></div>/**
542      * Return the index of the grid row which contains the passed HTMLElement.
543      * See also {@link #findCellIndex}
544      * @param {HTMLElement} el The target HTMLElement
545      * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
546      */
547     findRowIndex : function(el) {
548         var row = this.findRow(el);
549         return row ? row.rowIndex : false;
550     },
551
552     <div id="method-Ext.grid.GridView-findRowBody"></div>/**
553      * Return the HtmlElement representing the grid row body which contains the passed element.
554      * @param {HTMLElement} el The target HTMLElement
555      * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
556      */
557     findRowBody : function(el) {
558         if (!el) {
559             return false;
560         }
561         
562         return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
563     },
564
565     // getter methods for fetching elements dynamically in the grid
566
567     <div id="method-Ext.grid.GridView-getRow"></div>/**
568      * Return the <tt>&lt;div></tt> HtmlElement which represents a Grid row for the specified index.
569      * @param {Number} index The row index
570      * @return {HtmlElement} The div element.
571      */
572     getRow : function(row) {
573         return this.getRows()[row];
574     },
575
576     <div id="method-Ext.grid.GridView-getCell"></div>/**
577      * Returns the grid's <tt>&lt;td></tt> HtmlElement at the specified coordinates.
578      * @param {Number} row The row index in which to find the cell.
579      * @param {Number} col The column index of the cell.
580      * @return {HtmlElement} The td at the specified coordinates.
581      */
582     getCell : function(row, col) {
583         return Ext.fly(this.getRow(row)).query(this.cellSelector)[col]; 
584     },
585
586     <div id="method-Ext.grid.GridView-getHeaderCell"></div>/**
587      * Return the <tt>&lt;td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
588      * @param {Number} index The column index
589      * @return {HtmlElement} The td element.
590      */
591     getHeaderCell : function(index) {
592         return this.mainHd.dom.getElementsByTagName('td')[index];
593     },
594
595     // manipulating elements
596
597     // private - use getRowClass to apply custom row classes
598     addRowClass : function(rowId, cls) {
599         var row = this.getRow(rowId);
600         if (row) {
601             this.fly(row).addClass(cls);
602         }
603     },
604
605     // private
606     removeRowClass : function(row, cls) {
607         var r = this.getRow(row);
608         if(r){
609             this.fly(r).removeClass(cls);
610         }
611     },
612
613     // private
614     removeRow : function(row) {
615         Ext.removeNode(this.getRow(row));
616         this.syncFocusEl(row);
617     },
618
619     // private
620     removeRows : function(firstRow, lastRow) {
621         var bd = this.mainBody.dom,
622             rowIndex;
623             
624         for (rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
625             Ext.removeNode(bd.childNodes[firstRow]);
626         }
627         
628         this.syncFocusEl(firstRow);
629     },
630
631     /* ----------------------------------- Scrolling functions -------------------------------------------*/
632     
633     // private
634     getScrollState : function() {
635         var sb = this.scroller.dom;
636         
637         return {
638             left: sb.scrollLeft, 
639             top : sb.scrollTop
640         };
641     },
642
643     // private
644     restoreScroll : function(state) {
645         var sb = this.scroller.dom;
646         sb.scrollLeft = state.left;
647         sb.scrollTop  = state.top;
648     },
649
650     <div id="method-Ext.grid.GridView-scrollToTop"></div>/**
651      * Scrolls the grid to the top
652      */
653     scrollToTop : function() {
654         var dom = this.scroller.dom;
655         
656         dom.scrollTop  = 0;
657         dom.scrollLeft = 0;
658     },
659
660     // private
661     syncScroll : function() {
662         this.syncHeaderScroll();
663         var mb = this.scroller.dom;
664         this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
665     },
666
667     // private
668     syncHeaderScroll : function() {
669         var innerHd    = this.innerHd,
670             scrollLeft = this.scroller.dom.scrollLeft;
671         
672         innerHd.scrollLeft = scrollLeft;
673         innerHd.scrollLeft = scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
674     },
675     
676     /**
677      * @private
678      * Ensures the given column has the given icon class
679      */
680     updateSortIcon : function(col, dir) {
681         var sortClasses = this.sortClasses,
682             sortClass   = sortClasses[dir == "DESC" ? 1 : 0],
683             headers     = this.mainHd.select('td').removeClass(sortClasses);
684         
685         headers.item(col).addClass(sortClass);
686     },
687
688     /**
689      * @private
690      * Updates the size of every column and cell in the grid
691      */
692     updateAllColumnWidths : function() {
693         var totalWidth = this.getTotalWidth(),
694             colCount   = this.cm.getColumnCount(),
695             rows       = this.getRows(),
696             rowCount   = rows.length,
697             widths     = [],
698             row, rowFirstChild, trow, i, j;
699         
700         for (i = 0; i < colCount; i++) {
701             widths[i] = this.getColumnWidth(i);
702             this.getHeaderCell(i).style.width = widths[i];
703         }
704         
705         this.updateHeaderWidth();
706         
707         for (i = 0; i < rowCount; i++) {
708             row = rows[i];
709             row.style.width = totalWidth;
710             rowFirstChild = row.firstChild;
711             
712             if (rowFirstChild) {
713                 rowFirstChild.style.width = totalWidth;
714                 trow = rowFirstChild.rows[0];
715                 
716                 for (j = 0; j < colCount; j++) {
717                     trow.childNodes[j].style.width = widths[j];
718                 }
719             }
720         }
721         
722         this.onAllColumnWidthsUpdated(widths, totalWidth);
723     },
724
725     /**
726      * @private
727      * Called after a column's width has been updated, this resizes all of the cells for that column in each row
728      * @param {Number} column The column index
729      */
730     updateColumnWidth : function(column, width) {
731         var columnWidth = this.getColumnWidth(column),
732             totalWidth  = this.getTotalWidth(),
733             headerCell  = this.getHeaderCell(column),
734             nodes       = this.getRows(),
735             nodeCount   = nodes.length,
736             row, i, firstChild;
737         
738         this.updateHeaderWidth();
739         headerCell.style.width = columnWidth;
740         
741         for (i = 0; i < nodeCount; i++) {
742             row = nodes[i];
743             firstChild = row.firstChild;
744             
745             row.style.width = totalWidth;
746             if (firstChild) {
747                 firstChild.style.width = totalWidth;
748                 firstChild.rows[0].childNodes[column].style.width = columnWidth;
749             }
750         }
751         
752         this.onColumnWidthUpdated(column, columnWidth, totalWidth);
753     },
754     
755     /**
756      * @private
757      * Sets the hidden status of a given column.
758      * @param {Number} col The column index
759      * @param {Boolean} hidden True to make the column hidden
760      */
761     updateColumnHidden : function(col, hidden) {
762         var totalWidth = this.getTotalWidth(),
763             display    = hidden ? 'none' : '',
764             headerCell = this.getHeaderCell(col),
765             nodes      = this.getRows(),
766             nodeCount  = nodes.length,
767             row, rowFirstChild, i;
768         
769         this.updateHeaderWidth();
770         headerCell.style.display = display;
771         
772         for (i = 0; i < nodeCount; i++) {
773             row = nodes[i];
774             row.style.width = totalWidth;
775             rowFirstChild = row.firstChild;
776             
777             if (rowFirstChild) {
778                 rowFirstChild.style.width = totalWidth;
779                 rowFirstChild.rows[0].childNodes[col].style.display = display;
780             }
781         }
782         
783         this.onColumnHiddenUpdated(col, hidden, totalWidth);
784         delete this.lastViewWidth; //recalc
785         this.layout();
786     },
787
788     /**
789      * @private
790      * Renders all of the rows to a string buffer and returns the string. This is called internally
791      * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM.
792      * @param {Array} columns The column data acquired from getColumnData.
793      * @param {Array} records The array of records to render
794      * @param {Ext.data.Store} store The store to render the rows from
795      * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of
796      * the rows so this is used to maintain logic for striping etc
797      * @param {Number} colCount The total number of columns in the column model
798      * @param {Boolean} stripe True to stripe the rows
799      * @return {String} A string containing the HTML for the rendered rows
800      */
801     doRender : function(columns, records, store, startRow, colCount, stripe) {
802         var templates = this.templates,
803             cellTemplate = templates.cell,
804             rowTemplate = templates.row,
805             last = colCount - 1,
806             tstyle = 'width:' + this.getTotalWidth() + ';',
807             // buffers
808             rowBuffer = [],
809             colBuffer = [],
810             rowParams = {tstyle: tstyle},
811             meta = {},
812             len  = records.length,
813             alt,
814             column,
815             record, i, j, rowIndex;
816
817         //build up each row's HTML
818         for (j = 0; j < len; j++) {
819             record    = records[j];
820             colBuffer = [];
821
822             rowIndex = j + startRow;
823
824             //build up each column's HTML
825             for (i = 0; i < colCount; i++) {
826                 column = columns[i];
827                 
828                 meta.id    = column.id;
829                 meta.css   = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
830                 meta.attr  = meta.cellAttr = '';
831                 meta.style = column.style;
832                 meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
833
834                 if (Ext.isEmpty(meta.value)) {
835                     meta.value = '&#160;';
836                 }
837
838                 if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
839                     meta.css += ' x-grid3-dirty-cell';
840                 }
841
842                 colBuffer[colBuffer.length] = cellTemplate.apply(meta);
843             }
844
845             alt = [];
846             //set up row striping and row dirtiness CSS classes
847             if (stripe && ((rowIndex + 1) % 2 === 0)) {
848                 alt[0] = 'x-grid3-row-alt';
849             }
850
851             if (record.dirty) {
852                 alt[1] = ' x-grid3-dirty-row';
853             }
854
855             rowParams.cols = colCount;
856
857             if (this.getRowClass) {
858                 alt[2] = this.getRowClass(record, rowIndex, rowParams, store);
859             }
860
861             rowParams.alt   = alt.join(' ');
862             rowParams.cells = colBuffer.join('');
863
864             rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams);
865         }
866
867         return rowBuffer.join('');
868     },
869
870     /**
871      * @private
872      * Adds CSS classes and rowIndex to each row
873      * @param {Number} startRow The row to start from (defaults to 0)
874      */
875     processRows : function(startRow, skipStripe) {
876         if (!this.ds || this.ds.getCount() < 1) {
877             return;
878         }
879
880         var rows   = this.getRows(),
881             length = rows.length,
882             row, i;
883
884         skipStripe = skipStripe || !this.grid.stripeRows;
885         startRow   = startRow   || 0;
886
887         for (i = 0; i < length; i++) {
888             row = rows[i];
889             if (row) {
890                 row.rowIndex = i;
891                 if (!skipStripe) {
892                     row.className = row.className.replace(this.rowClsRe, ' ');
893                     if ((i + 1) % 2 === 0){
894                         row.className += ' x-grid3-row-alt';
895                     }
896                 }
897             }
898         }
899
900         // add first/last-row classes
901         if (startRow === 0) {
902             Ext.fly(rows[0]).addClass(this.firstRowCls);
903         }
904
905         Ext.fly(rows[length - 1]).addClass(this.lastRowCls);
906     },
907     
908     /**
909      * @private
910      */
911     afterRender : function() {
912         if (!this.ds || !this.cm) {
913             return;
914         }
915         
916         this.mainBody.dom.innerHTML = this.renderBody() || '&#160;';
917         this.processRows(0, true);
918
919         if (this.deferEmptyText !== true) {
920             this.applyEmptyText();
921         }
922         
923         this.grid.fireEvent('viewready', this.grid);
924     },
925     
926     /**
927      * @private
928      * This is always intended to be called after renderUI. Sets up listeners on the UI elements
929      * and sets up options like column menus, moving and resizing.
930      */
931     afterRenderUI: function() {
932         var grid = this.grid;
933         
934         this.initElements();
935
936         // get mousedowns early
937         Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
938
939         this.mainHd.on({
940             scope    : this,
941             mouseover: this.handleHdOver,
942             mouseout : this.handleHdOut,
943             mousemove: this.handleHdMove
944         });
945
946         this.scroller.on('scroll', this.syncScroll,  this);
947         
948         if (grid.enableColumnResize !== false) {
949             this.splitZone = new Ext.grid.GridView.SplitDragZone(grid, this.mainHd.dom);
950         }
951
952         if (grid.enableColumnMove) {
953             this.columnDrag = new Ext.grid.GridView.ColumnDragZone(grid, this.innerHd);
954             this.columnDrop = new Ext.grid.HeaderDropZone(grid, this.mainHd.dom);
955         }
956
957         if (grid.enableHdMenu !== false) {
958             this.hmenu = new Ext.menu.Menu({id: grid.id + '-hctx'});
959             this.hmenu.add(
960                 {itemId:'asc',  text: this.sortAscText,  cls: 'xg-hmenu-sort-asc'},
961                 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
962             );
963
964             if (grid.enableColumnHide !== false) {
965                 this.colMenu = new Ext.menu.Menu({id:grid.id + '-hcols-menu'});
966                 this.colMenu.on({
967                     scope     : this,
968                     beforeshow: this.beforeColMenuShow,
969                     itemclick : this.handleHdMenuClick
970                 });
971                 this.hmenu.add('-', {
972                     itemId:'columns',
973                     hideOnClick: false,
974                     text: this.columnsText,
975                     menu: this.colMenu,
976                     iconCls: 'x-cols-icon'
977                 });
978             }
979
980             this.hmenu.on('itemclick', this.handleHdMenuClick, this);
981         }
982
983         if (grid.trackMouseOver) {
984             this.mainBody.on({
985                 scope    : this,
986                 mouseover: this.onRowOver,
987                 mouseout : this.onRowOut
988             });
989         }
990
991         if (grid.enableDragDrop || grid.enableDrag) {
992             this.dragZone = new Ext.grid.GridDragZone(grid, {
993                 ddGroup : grid.ddGroup || 'GridDD'
994             });
995         }
996
997         this.updateHeaderSortState();
998     },
999
1000     /**
1001      * @private
1002      * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not
1003      * render rows from the store, just the surrounding UI elements.
1004      */
1005     renderUI : function() {
1006         var templates = this.templates;
1007
1008         return templates.master.apply({
1009             body  : templates.body.apply({rows:'&#160;'}),
1010             header: this.renderHeaders(),
1011             ostyle: 'width:' + this.getOffsetWidth() + ';',
1012             bstyle: 'width:' + this.getTotalWidth()  + ';'
1013         });
1014     },
1015
1016     // private
1017     processEvent : function(name, e) {
1018         var target = e.getTarget(),
1019             grid   = this.grid,
1020             header = this.findHeaderIndex(target),
1021             row, cell, col, body;
1022
1023         grid.fireEvent(name, e);
1024
1025         if (header !== false) {
1026             grid.fireEvent('header' + name, grid, header, e);
1027         } else {
1028             row = this.findRowIndex(target);
1029
1030 //          Grid's value-added events must bubble correctly to allow cancelling via returning false: cell->column->row
1031 //          We must allow a return of false at any of these levels to cancel the event processing.
1032 //          Particularly allowing rowmousedown to be cancellable by prior handlers which need to prevent selection.
1033             if (row !== false) {
1034                 cell = this.findCellIndex(target);
1035                 if (cell !== false) {
1036                     col = grid.colModel.getColumnAt(cell);
1037                     if (grid.fireEvent('cell' + name, grid, row, cell, e) !== false) {
1038                         if (!col || (col.processEvent && (col.processEvent(name, e, grid, row, cell) !== false))) {
1039                             grid.fireEvent('row' + name, grid, row, e);
1040                         }
1041                     }
1042                 } else {
1043                     if (grid.fireEvent('row' + name, grid, row, e) !== false) {
1044                         (body = this.findRowBody(target)) && grid.fireEvent('rowbody' + name, grid, row, e);
1045                     }
1046                 }
1047             } else {
1048                 grid.fireEvent('container' + name, grid, e);
1049             }
1050         }
1051     },
1052
1053     /**
1054      * @private
1055      * Sizes the grid's header and body elements
1056      */
1057     layout : function(initial) {
1058         if (!this.mainBody) {
1059             return; // not rendered
1060         }
1061
1062         var grid       = this.grid,
1063             gridEl     = grid.getGridEl(),
1064             gridSize   = gridEl.getSize(true),
1065             gridWidth  = gridSize.width,
1066             gridHeight = gridSize.height,
1067             scroller   = this.scroller,
1068             scrollStyle, headerHeight, scrollHeight;
1069         
1070         if (gridWidth < 20 || gridHeight < 20) {
1071             return;
1072         }
1073         
1074         if (grid.autoHeight) {
1075             scrollStyle = scroller.dom.style;
1076             scrollStyle.overflow = 'visible';
1077             
1078             if (Ext.isWebKit) {
1079                 scrollStyle.position = 'static';
1080             }
1081         } else {
1082             this.el.setSize(gridWidth, gridHeight);
1083             
1084             headerHeight = this.mainHd.getHeight();
1085             scrollHeight = gridHeight - headerHeight;
1086             
1087             scroller.setSize(gridWidth, scrollHeight);
1088             
1089             if (this.innerHd) {
1090                 this.innerHd.style.width = (gridWidth) + "px";
1091             }
1092         }
1093         
1094         if (this.forceFit || (initial === true && this.autoFill)) {
1095             if (this.lastViewWidth != gridWidth) {
1096                 this.fitColumns(false, false);
1097                 this.lastViewWidth = gridWidth;
1098             }
1099         } else {
1100             this.autoExpand();
1101             this.syncHeaderScroll();
1102         }
1103         
1104         this.onLayout(gridWidth, scrollHeight);
1105     },
1106
1107     // template functions for subclasses and plugins
1108     // these functions include precalculated values
1109     onLayout : function(vw, vh) {
1110         // do nothing
1111     },
1112
1113     onColumnWidthUpdated : function(col, w, tw) {
1114         //template method
1115     },
1116
1117     onAllColumnWidthsUpdated : function(ws, tw) {
1118         //template method
1119     },
1120
1121     onColumnHiddenUpdated : function(col, hidden, tw) {
1122         // template method
1123     },
1124
1125     updateColumnText : function(col, text) {
1126         // template method
1127     },
1128
1129     afterMove : function(colIndex) {
1130         // template method
1131     },
1132
1133     /* ----------------------------------- Core Specific -------------------------------------------*/
1134     // private
1135     init : function(grid) {
1136         this.grid = grid;
1137
1138         this.initTemplates();
1139         this.initData(grid.store, grid.colModel);
1140         this.initUI(grid);
1141     },
1142
1143     // private
1144     getColumnId : function(index){
1145         return this.cm.getColumnId(index);
1146     },
1147
1148     // private
1149     getOffsetWidth : function() {
1150         return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
1151     },
1152
1153     // private
1154     getScrollOffset: function() {
1155         return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
1156     },
1157
1158     /**
1159      * @private
1160      * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just
1161      * returns a string.
1162      * @return {String} Rendered header row
1163      */
1164     renderHeaders : function() {
1165         var colModel   = this.cm,
1166             templates  = this.templates,
1167             headerTpl  = templates.hcell,
1168             properties = {},
1169             colCount   = colModel.getColumnCount(),
1170             last       = colCount - 1,
1171             cells      = [],
1172             i, cssCls;
1173         
1174         for (i = 0; i < colCount; i++) {
1175             if (i == 0) {
1176                 cssCls = 'x-grid3-cell-first ';
1177             } else {
1178                 cssCls = i == last ? 'x-grid3-cell-last ' : '';
1179             }
1180             
1181             properties = {
1182                 id     : colModel.getColumnId(i),
1183                 value  : colModel.getColumnHeader(i) || '',
1184                 style  : this.getColumnStyle(i, true),
1185                 css    : cssCls,
1186                 tooltip: this.getColumnTooltip(i)
1187             };
1188             
1189             if (colModel.config[i].align == 'right') {
1190                 properties.istyle = 'padding-right: 16px;';
1191             } else {
1192                 delete properties.istyle;
1193             }
1194             
1195             cells[i] = headerTpl.apply(properties);
1196         }
1197         
1198         return templates.header.apply({
1199             cells : cells.join(""),
1200             tstyle: String.format("width: {0};", this.getTotalWidth())
1201         });
1202     },
1203
1204     /**
1205      * @private
1206      */
1207     getColumnTooltip : function(i) {
1208         var tooltip = this.cm.getColumnTooltip(i);
1209         if (tooltip) {
1210             if (Ext.QuickTips.isEnabled()) {
1211                 return 'ext:qtip="' + tooltip + '"';
1212             } else {
1213                 return 'title="' + tooltip + '"';
1214             }
1215         }
1216         
1217         return '';
1218     },
1219
1220     // private
1221     beforeUpdate : function() {
1222         this.grid.stopEditing(true);
1223     },
1224
1225     /**
1226      * @private
1227      * Re-renders the headers and ensures they are sized correctly
1228      */
1229     updateHeaders : function() {
1230         this.innerHd.firstChild.innerHTML = this.renderHeaders();
1231         
1232         this.updateHeaderWidth(false);
1233     },
1234     
1235     /**
1236      * @private
1237      * Ensures that the header is sized to the total width available to it
1238      * @param {Boolean} updateMain True to update the mainBody's width also (defaults to true)
1239      */
1240     updateHeaderWidth: function(updateMain) {
1241         var innerHdChild = this.innerHd.firstChild,
1242             totalWidth   = this.getTotalWidth();
1243         
1244         innerHdChild.style.width = this.getOffsetWidth();
1245         innerHdChild.firstChild.style.width = totalWidth;
1246         
1247         if (updateMain !== false) {
1248             this.mainBody.dom.style.width = totalWidth;
1249         }
1250     },
1251
1252     <div id="method-Ext.grid.GridView-focusRow"></div>/**
1253      * Focuses the specified row.
1254      * @param {Number} row The row index
1255      */
1256     focusRow : function(row) {
1257         this.focusCell(row, 0, false);
1258     },
1259
1260     <div id="method-Ext.grid.GridView-focusCell"></div>/**
1261      * Focuses the specified cell.
1262      * @param {Number} row The row index
1263      * @param {Number} col The column index
1264      */
1265     focusCell : function(row, col, hscroll) {
1266         this.syncFocusEl(this.ensureVisible(row, col, hscroll));
1267         
1268         var focusEl = this.focusEl;
1269         
1270         if (Ext.isGecko) {
1271             focusEl.focus();
1272         } else {
1273             focusEl.focus.defer(1, focusEl);
1274         }
1275     },
1276
1277     /**
1278      * @private
1279      * Finds the Elements corresponding to the given row and column indexes
1280      */
1281     resolveCell : function(row, col, hscroll) {
1282         if (!Ext.isNumber(row)) {
1283             row = row.rowIndex;
1284         }
1285         
1286         if (!this.ds) {
1287             return null;
1288         }
1289         
1290         if (row < 0 || row >= this.ds.getCount()) {
1291             return null;
1292         }
1293         col = (col !== undefined ? col : 0);
1294
1295         var rowEl    = this.getRow(row),
1296             colModel = this.cm,
1297             colCount = colModel.getColumnCount(),
1298             cellEl;
1299             
1300         if (!(hscroll === false && col === 0)) {
1301             while (col < colCount && colModel.isHidden(col)) {
1302                 col++;
1303             }
1304             
1305             cellEl = this.getCell(row, col);
1306         }
1307
1308         return {row: rowEl, cell: cellEl};
1309     },
1310
1311     /**
1312      * @private
1313      * Returns the XY co-ordinates of a given row/cell resolution (see {@link #resolveCell})
1314      * @return {Array} X and Y coords
1315      */
1316     getResolvedXY : function(resolved) {
1317         if (!resolved) {
1318             return null;
1319         }
1320         
1321         var cell = resolved.cell,
1322             row  = resolved.row;
1323         
1324         if (cell) {
1325             return Ext.fly(cell).getXY();
1326         } else {
1327             return [this.el.getX(), Ext.fly(row).getY()];
1328         }
1329     },
1330
1331     /**
1332      * @private
1333      * Moves the focus element to the x and y co-ordinates of the given row and column
1334      */
1335     syncFocusEl : function(row, col, hscroll) {
1336         var xy = row;
1337         
1338         if (!Ext.isArray(xy)) {
1339             row = Math.min(row, Math.max(0, this.getRows().length-1));
1340             
1341             if (isNaN(row)) {
1342                 return;
1343             }
1344             
1345             xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
1346         }
1347         
1348         this.focusEl.setXY(xy || this.scroller.getXY());
1349     },
1350
1351     /**
1352      * @private
1353      */
1354     ensureVisible : function(row, col, hscroll) {
1355         var resolved = this.resolveCell(row, col, hscroll);
1356         
1357         if (!resolved || !resolved.row) {
1358             return null;
1359         }
1360
1361         var rowEl  = resolved.row,
1362             cellEl = resolved.cell,
1363             c = this.scroller.dom,
1364             p = rowEl,
1365             ctop = 0,
1366             stop = this.el.dom;
1367
1368         while (p && p != stop) {
1369             ctop += p.offsetTop;
1370             p = p.offsetParent;
1371         }
1372
1373         ctop -= this.mainHd.dom.offsetHeight;
1374         stop = parseInt(c.scrollTop, 10);
1375
1376         var cbot = ctop + rowEl.offsetHeight,
1377             ch = c.clientHeight,
1378             sbot = stop + ch;
1379
1380
1381         if (ctop < stop) {
1382           c.scrollTop = ctop;
1383         } else if(cbot > sbot) {
1384             c.scrollTop = cbot-ch;
1385         }
1386
1387         if (hscroll !== false) {
1388             var cleft  = parseInt(cellEl.offsetLeft, 10),
1389                 cright = cleft + cellEl.offsetWidth,
1390                 sleft  = parseInt(c.scrollLeft, 10),
1391                 sright = sleft + c.clientWidth;
1392                 
1393             if (cleft < sleft) {
1394                 c.scrollLeft = cleft;
1395             } else if(cright > sright) {
1396                 c.scrollLeft = cright-c.clientWidth;
1397             }
1398         }
1399         
1400         return this.getResolvedXY(resolved);
1401     },
1402
1403     // private
1404     insertRows : function(dm, firstRow, lastRow, isUpdate) {
1405         var last = dm.getCount() - 1;
1406         if( !isUpdate && firstRow === 0 && lastRow >= last) {
1407             this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1408                 this.refresh();
1409             this.fireEvent('rowsinserted', this, firstRow, lastRow);
1410         } else {
1411             if (!isUpdate) {
1412                 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1413             }
1414             var html = this.renderRows(firstRow, lastRow),
1415                 before = this.getRow(firstRow);
1416             if (before) {
1417                 if(firstRow === 0){
1418                     Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
1419                 }
1420                 Ext.DomHelper.insertHtml('beforeBegin', before, html);
1421             } else {
1422                 var r = this.getRow(last - 1);
1423                 if(r){
1424                     Ext.fly(r).removeClass(this.lastRowCls);
1425                 }
1426                 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
1427             }
1428             if (!isUpdate) {
1429                 this.fireEvent('rowsinserted', this, firstRow, lastRow);
1430                 this.processRows(firstRow);
1431             } else if (firstRow === 0 || firstRow >= last) {
1432                 //ensure first/last row is kept after an update.
1433                 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
1434             }
1435         }
1436         this.syncFocusEl(firstRow);
1437     },
1438
1439     /**
1440      * @private
1441      * DEPRECATED - this doesn't appear to be called anywhere in the library, remove in 4.0. 
1442      */
1443     deleteRows : function(dm, firstRow, lastRow) {
1444         if (dm.getRowCount() < 1) {
1445             this.refresh();
1446         } else {
1447             this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
1448
1449             this.removeRows(firstRow, lastRow);
1450
1451             this.processRows(firstRow);
1452             this.fireEvent('rowsdeleted', this, firstRow, lastRow);
1453         }
1454     },
1455
1456     /**
1457      * @private
1458      * Builds a CSS string for the given column index
1459      * @param {Number} colIndex The column index
1460      * @param {Boolean} isHeader True if getting the style for the column's header
1461      * @return {String} The CSS string
1462      */
1463     getColumnStyle : function(colIndex, isHeader) {
1464         var colModel  = this.cm,
1465             colConfig = colModel.config,
1466             style     = isHeader ? '' : colConfig[colIndex].css || '',
1467             align     = colConfig[colIndex].align;
1468         
1469         style += String.format("width: {0};", this.getColumnWidth(colIndex));
1470         
1471         if (colModel.isHidden(colIndex)) {
1472             style += 'display: none; ';
1473         }
1474         
1475         if (align) {
1476             style += String.format("text-align: {0};", align);
1477         }
1478         
1479         return style;
1480     },
1481
1482     /**
1483      * @private
1484      * Returns the width of a given column minus its border width
1485      * @return {Number} The column index
1486      * @return {String|Number} The width in pixels
1487      */
1488     getColumnWidth : function(column) {
1489         var columnWidth = this.cm.getColumnWidth(column),
1490             borderWidth = this.borderWidth;
1491         
1492         if (Ext.isNumber(columnWidth)) {
1493             if (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2)) {
1494                 return columnWidth + "px";
1495             } else {
1496                 return Math.max(columnWidth - borderWidth, 0) + "px";
1497             }
1498         } else {
1499             return columnWidth;
1500         }
1501     },
1502
1503     /**
1504      * @private
1505      * Returns the total width of all visible columns
1506      * @return {String} 
1507      */
1508     getTotalWidth : function() {
1509         return this.cm.getTotalWidth() + 'px';
1510     },
1511
1512     /**
1513      * @private
1514      * Resizes each column to fit the available grid width.
1515      * TODO: The second argument isn't even used, remove it in 4.0
1516      * @param {Boolean} preventRefresh True to prevent resizing of each row to the new column sizes (defaults to false)
1517      * @param {null} onlyExpand NOT USED, will be removed in 4.0
1518      * @param {Number} omitColumn The index of a column to leave at its current width. Defaults to undefined
1519      * @return {Boolean} True if the operation succeeded, false if not or undefined if the grid view is not yet initialized
1520      */
1521     fitColumns : function(preventRefresh, onlyExpand, omitColumn) {
1522         var grid          = this.grid,
1523             colModel      = this.cm,
1524             totalColWidth = colModel.getTotalWidth(false),
1525             gridWidth     = this.getGridInnerWidth(),
1526             extraWidth    = gridWidth - totalColWidth,
1527             columns       = [],
1528             extraCol      = 0,
1529             width         = 0,
1530             colWidth, fraction, i;
1531         
1532         // not initialized, so don't screw up the default widths
1533         if (gridWidth < 20 || extraWidth === 0) {
1534             return false;
1535         }
1536         
1537         var visibleColCount = colModel.getColumnCount(true),
1538             totalColCount   = colModel.getColumnCount(false),
1539             adjCount        = visibleColCount - (Ext.isNumber(omitColumn) ? 1 : 0);
1540         
1541         if (adjCount === 0) {
1542             adjCount = 1;
1543             omitColumn = undefined;
1544         }
1545         
1546         //FIXME: the algorithm used here is odd and potentially confusing. Includes this for loop and the while after it.
1547         for (i = 0; i < totalColCount; i++) {
1548             if (!colModel.isFixed(i) && i !== omitColumn) {
1549                 colWidth = colModel.getColumnWidth(i);
1550                 columns.push(i, colWidth);
1551                 
1552                 if (!colModel.isHidden(i)) {
1553                     extraCol = i;
1554                     width += colWidth;
1555                 }
1556             }
1557         }
1558         
1559         fraction = (gridWidth - colModel.getTotalWidth()) / width;
1560         
1561         while (columns.length) {
1562             colWidth = columns.pop();
1563             i        = columns.pop();
1564             
1565             colModel.setColumnWidth(i, Math.max(grid.minColumnWidth, Math.floor(colWidth + colWidth * fraction)), true);
1566         }
1567         
1568         //this has been changed above so remeasure now
1569         totalColWidth = colModel.getTotalWidth(false);
1570         
1571         if (totalColWidth > gridWidth) {
1572             var adjustCol = (adjCount == visibleColCount) ? extraCol : omitColumn,
1573                 newWidth  = Math.max(1, colModel.getColumnWidth(adjustCol) - (totalColWidth - gridWidth));
1574             
1575             colModel.setColumnWidth(adjustCol, newWidth, true);
1576         }
1577         
1578         if (preventRefresh !== true) {
1579             this.updateAllColumnWidths();
1580         }
1581         
1582         return true;
1583     },
1584
1585     /**
1586      * @private
1587      * Resizes the configured autoExpandColumn to take the available width after the other columns have 
1588      * been accounted for
1589      * @param {Boolean} preventUpdate True to prevent the resizing of all rows (defaults to false)
1590      */
1591     autoExpand : function(preventUpdate) {
1592         var grid             = this.grid,
1593             colModel         = this.cm,
1594             gridWidth        = this.getGridInnerWidth(),
1595             totalColumnWidth = colModel.getTotalWidth(false),
1596             autoExpandColumn = grid.autoExpandColumn;
1597         
1598         if (!this.userResized && autoExpandColumn) {
1599             if (gridWidth != totalColumnWidth) {
1600                 //if we are not already using all available width, resize the autoExpandColumn
1601                 var colIndex     = colModel.getIndexById(autoExpandColumn),
1602                     currentWidth = colModel.getColumnWidth(colIndex),
1603                     desiredWidth = gridWidth - totalColumnWidth + currentWidth,
1604                     newWidth     = Math.min(Math.max(desiredWidth, grid.autoExpandMin), grid.autoExpandMax);
1605                 
1606                 if (currentWidth != newWidth) {
1607                     colModel.setColumnWidth(colIndex, newWidth, true);
1608                     
1609                     if (preventUpdate !== true) {
1610                         this.updateColumnWidth(colIndex, newWidth);
1611                     }
1612                 }
1613             }
1614         }
1615     },
1616     
1617     <div id="method-Ext.grid.GridView-getGridInnerWidth"></div>/**
1618      * Returns the total internal width available to the grid, taking the scrollbar into account
1619      * @return {Number} The total width
1620      */
1621     getGridInnerWidth: function() {
1622         return this.grid.getGridEl().getWidth(true) - this.getScrollOffset();
1623     },
1624
1625     /**
1626      * @private
1627      * Returns an array of column configurations - one for each column
1628      * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
1629      */
1630     getColumnData : function() {
1631         var columns  = [],
1632             colModel = this.cm,
1633             colCount = colModel.getColumnCount(),
1634             fields   = this.ds.fields,
1635             i, name;
1636         
1637         for (i = 0; i < colCount; i++) {
1638             name = colModel.getDataIndex(i);
1639             
1640             columns[i] = {
1641                 name    : Ext.isDefined(name) ? name : (fields.get(i) ? fields.get(i).name : undefined),
1642                 renderer: colModel.getRenderer(i),
1643                 scope   : colModel.getRendererScope(i),
1644                 id      : colModel.getColumnId(i),
1645                 style   : this.getColumnStyle(i)
1646             };
1647         }
1648         
1649         return columns;
1650     },
1651
1652     /**
1653      * @private
1654      * Renders rows between start and end indexes
1655      * @param {Number} startRow Index of the first row to render
1656      * @param {Number} endRow Index of the last row to render
1657      */
1658     renderRows : function(startRow, endRow) {
1659         var grid     = this.grid,
1660             store    = grid.store,
1661             stripe   = grid.stripeRows,
1662             colModel = grid.colModel,
1663             colCount = colModel.getColumnCount(),
1664             rowCount = store.getCount(),
1665             records;
1666         
1667         if (rowCount < 1) {
1668             return '';
1669         }
1670         
1671         startRow = startRow || 0;
1672         endRow   = Ext.isDefined(endRow) ? endRow : rowCount - 1;
1673         records  = store.getRange(startRow, endRow);
1674         
1675         return this.doRender(this.getColumnData(), records, store, startRow, colCount, stripe);
1676     },
1677
1678     // private
1679     renderBody : function(){
1680         var markup = this.renderRows() || '&#160;';
1681         return this.templates.body.apply({rows: markup});
1682     },
1683
1684     /**
1685      * @private
1686      * Refreshes a row by re-rendering it. Fires the rowupdated event when done
1687      */
1688     refreshRow: function(record) {
1689         var store     = this.ds,
1690             colCount  = this.cm.getColumnCount(),
1691             columns   = this.getColumnData(),
1692             last      = colCount - 1,
1693             cls       = ['x-grid3-row'],
1694             rowParams = {
1695                 tstyle: String.format("width: {0};", this.getTotalWidth())
1696             },
1697             colBuffer = [],
1698             cellTpl   = this.templates.cell,
1699             rowIndex, row, column, meta, css, i;
1700         
1701         if (Ext.isNumber(record)) {
1702             rowIndex = record;
1703             record   = store.getAt(rowIndex);
1704         } else {
1705             rowIndex = store.indexOf(record);
1706         }
1707         
1708         //the record could not be found
1709         if (!record || rowIndex < 0) {
1710             return;
1711         }
1712         
1713         //builds each column in this row
1714         for (i = 0; i < colCount; i++) {
1715             column = columns[i];
1716             
1717             if (i == 0) {
1718                 css = 'x-grid3-cell-first';
1719             } else {
1720                 css = (i == last) ? 'x-grid3-cell-last ' : '';
1721             }
1722             
1723             meta = {
1724                 id      : column.id,
1725                 style   : column.style,
1726                 css     : css,
1727                 attr    : "",
1728                 cellAttr: ""
1729             };
1730             // Need to set this after, because we pass meta to the renderer
1731             meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
1732             
1733             if (Ext.isEmpty(meta.value)) {
1734                 meta.value = '&#160;';
1735             }
1736             
1737             if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
1738                 meta.css += ' x-grid3-dirty-cell';
1739             }
1740             
1741             colBuffer[i] = cellTpl.apply(meta);
1742         }
1743         
1744         row = this.getRow(rowIndex);
1745         row.className = '';
1746         
1747         if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
1748             cls.push('x-grid3-row-alt');
1749         }
1750         
1751         if (this.getRowClass) {
1752             rowParams.cols = colCount;
1753             cls.push(this.getRowClass(record, rowIndex, rowParams, store));
1754         }
1755         
1756         this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
1757         rowParams.cells = colBuffer.join("");
1758         row.innerHTML = this.templates.rowInner.apply(rowParams);
1759         
1760         this.fireEvent('rowupdated', this, rowIndex, record);
1761     },
1762
1763     <div id="method-Ext.grid.GridView-refresh"></div>/**
1764      * Refreshs the grid UI
1765      * @param {Boolean} headersToo (optional) True to also refresh the headers
1766      */
1767     refresh : function(headersToo) {
1768         this.fireEvent('beforerefresh', this);
1769         this.grid.stopEditing(true);
1770
1771         var result = this.renderBody();
1772         this.mainBody.update(result).setWidth(this.getTotalWidth());
1773         if (headersToo === true) {
1774             this.updateHeaders();
1775             this.updateHeaderSortState();
1776         }
1777         this.processRows(0, true);
1778         this.layout();
1779         this.applyEmptyText();
1780         this.fireEvent('refresh', this);
1781     },
1782
1783     /**
1784      * @private
1785      * Displays the configured emptyText if there are currently no rows to display
1786      */
1787     applyEmptyText : function() {
1788         if (this.emptyText && !this.hasRows()) {
1789             this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1790         }
1791     },
1792
1793     /**
1794      * @private
1795      * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
1796      * if the sorting has changed since this function was last run.
1797      */
1798     updateHeaderSortState : function() {
1799         var state = this.ds.getSortState();
1800         if (!state) {
1801             return;
1802         }
1803
1804         if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
1805             this.grid.fireEvent('sortchange', this.grid, state);
1806         }
1807
1808         this.sortState = state;
1809
1810         var sortColumn = this.cm.findColumnIndex(state.field);
1811         if (sortColumn != -1) {
1812             var sortDir = state.direction;
1813             this.updateSortIcon(sortColumn, sortDir);
1814         }
1815     },
1816
1817     /**
1818      * @private
1819      * Removes any sorting indicator classes from the column headers
1820      */
1821     clearHeaderSortState : function() {
1822         if (!this.sortState) {
1823             return;
1824         }
1825         this.grid.fireEvent('sortchange', this.grid, null);
1826         this.mainHd.select('td').removeClass(this.sortClasses);
1827         delete this.sortState;
1828     },
1829
1830     /**
1831      * @private
1832      * Destroys all objects associated with the GridView
1833      */
1834     destroy : function() {
1835         var me              = this,
1836             grid            = me.grid,
1837             gridEl          = grid.getGridEl(),
1838             dragZone        = me.dragZone,
1839             splitZone       = me.splitZone,
1840             columnDrag      = me.columnDrag,
1841             columnDrop      = me.columnDrop,
1842             scrollToTopTask = me.scrollToTopTask,
1843             columnDragData,
1844             columnDragProxy;
1845         
1846         if (scrollToTopTask && scrollToTopTask.cancel) {
1847             scrollToTopTask.cancel();
1848         }
1849         
1850         Ext.destroyMembers(me, 'colMenu', 'hmenu');
1851
1852         me.initData(null, null);
1853         me.purgeListeners();
1854         
1855         Ext.fly(me.innerHd).un("click", me.handleHdDown, me);
1856
1857         if (grid.enableColumnMove) {
1858             columnDragData = columnDrag.dragData;
1859             columnDragProxy = columnDrag.proxy;
1860             Ext.destroy(
1861                 columnDrag.el,
1862                 columnDragProxy.ghost,
1863                 columnDragProxy.el,
1864                 columnDrop.el,
1865                 columnDrop.proxyTop,
1866                 columnDrop.proxyBottom,
1867                 columnDragData.ddel,
1868                 columnDragData.header
1869             );
1870             
1871             if (columnDragProxy.anim) {
1872                 Ext.destroy(columnDragProxy.anim);
1873             }
1874             
1875             delete columnDragProxy.ghost;
1876             delete columnDragData.ddel;
1877             delete columnDragData.header;
1878             columnDrag.destroy();
1879             
1880             delete Ext.dd.DDM.locationCache[columnDrag.id];
1881             delete columnDrag._domRef;
1882
1883             delete columnDrop.proxyTop;
1884             delete columnDrop.proxyBottom;
1885             columnDrop.destroy();
1886             delete Ext.dd.DDM.locationCache["gridHeader" + gridEl.id];
1887             delete columnDrop._domRef;
1888             delete Ext.dd.DDM.ids[columnDrop.ddGroup];
1889         }
1890
1891         if (splitZone) { // enableColumnResize
1892             splitZone.destroy();
1893             delete splitZone._domRef;
1894             delete Ext.dd.DDM.ids["gridSplitters" + gridEl.id];
1895         }
1896
1897         Ext.fly(me.innerHd).removeAllListeners();
1898         Ext.removeNode(me.innerHd);
1899         delete me.innerHd;
1900
1901         Ext.destroy(
1902             me.el,
1903             me.mainWrap,
1904             me.mainHd,
1905             me.scroller,
1906             me.mainBody,
1907             me.focusEl,
1908             me.resizeMarker,
1909             me.resizeProxy,
1910             me.activeHdBtn,
1911             me._flyweight,
1912             dragZone,
1913             splitZone
1914         );
1915
1916         delete grid.container;
1917
1918         if (dragZone) {
1919             dragZone.destroy();
1920         }
1921
1922         Ext.dd.DDM.currentTarget = null;
1923         delete Ext.dd.DDM.locationCache[gridEl.id];
1924
1925         Ext.EventManager.removeResizeListener(me.onWindowResize, me);
1926     },
1927
1928     // private
1929     onDenyColumnHide : function() {
1930
1931     },
1932
1933     // private
1934     render : function() {
1935         if (this.autoFill) {
1936             var ct = this.grid.ownerCt;
1937             
1938             if (ct && ct.getLayout()) {
1939                 ct.on('afterlayout', function() {
1940                     this.fitColumns(true, true);
1941                     this.updateHeaders();
1942                     this.updateHeaderSortState();
1943                 }, this, {single: true});
1944             }
1945         } else if (this.forceFit) {
1946             this.fitColumns(true, false);
1947         } else if (this.grid.autoExpandColumn) {
1948             this.autoExpand(true);
1949         }
1950         
1951         this.grid.getGridEl().dom.innerHTML = this.renderUI();
1952         
1953         this.afterRenderUI();
1954     },
1955
1956     /* --------------------------------- Model Events and Handlers --------------------------------*/
1957     
1958     /**
1959      * @private
1960      * Binds a new Store and ColumnModel to this GridView. Removes any listeners from the old objects (if present)
1961      * and adds listeners to the new ones
1962      * @param {Ext.data.Store} newStore The new Store instance
1963      * @param {Ext.grid.ColumnModel} newColModel The new ColumnModel instance
1964      */
1965     initData : function(newStore, newColModel) {
1966         var me = this;
1967         
1968         if (me.ds) {
1969             var oldStore = me.ds;
1970             
1971             oldStore.un('add', me.onAdd, me);
1972             oldStore.un('load', me.onLoad, me);
1973             oldStore.un('clear', me.onClear, me);
1974             oldStore.un('remove', me.onRemove, me);
1975             oldStore.un('update', me.onUpdate, me);
1976             oldStore.un('datachanged', me.onDataChange, me);
1977             
1978             if (oldStore !== newStore && oldStore.autoDestroy) {
1979                 oldStore.destroy();
1980             }
1981         }
1982         
1983         if (newStore) {
1984             newStore.on({
1985                 scope      : me,
1986                 load       : me.onLoad,
1987                 add        : me.onAdd,
1988                 remove     : me.onRemove,
1989                 update     : me.onUpdate,
1990                 clear      : me.onClear,
1991                 datachanged: me.onDataChange
1992             });
1993         }
1994         
1995         if (me.cm) {
1996             var oldColModel = me.cm;
1997             
1998             oldColModel.un('configchange', me.onColConfigChange, me);
1999             oldColModel.un('widthchange',  me.onColWidthChange, me);
2000             oldColModel.un('headerchange', me.onHeaderChange, me);
2001             oldColModel.un('hiddenchange', me.onHiddenChange, me);
2002             oldColModel.un('columnmoved',  me.onColumnMove, me);
2003         }
2004         
2005         if (newColModel) {
2006             delete me.lastViewWidth;
2007             
2008             newColModel.on({
2009                 scope       : me,
2010                 configchange: me.onColConfigChange,
2011                 widthchange : me.onColWidthChange,
2012                 headerchange: me.onHeaderChange,
2013                 hiddenchange: me.onHiddenChange,
2014                 columnmoved : me.onColumnMove
2015             });
2016         }
2017         
2018         me.ds = newStore;
2019         me.cm = newColModel;
2020     },
2021
2022     // private
2023     onDataChange : function(){
2024         this.refresh(true);
2025         this.updateHeaderSortState();
2026         this.syncFocusEl(0);
2027     },
2028
2029     // private
2030     onClear : function() {
2031         this.refresh();
2032         this.syncFocusEl(0);
2033     },
2034
2035     // private
2036     onUpdate : function(store, record) {
2037         this.refreshRow(record);
2038     },
2039
2040     // private
2041     onAdd : function(store, records, index) {
2042         this.insertRows(store, index, index + (records.length-1));
2043     },
2044
2045     // private
2046     onRemove : function(store, record, index, isUpdate) {
2047         if (isUpdate !== true) {
2048             this.fireEvent('beforerowremoved', this, index, record);
2049         }
2050         
2051         this.removeRow(index);
2052         
2053         if (isUpdate !== true) {
2054             this.processRows(index);
2055             this.applyEmptyText();
2056             this.fireEvent('rowremoved', this, index, record);
2057         }
2058     },
2059
2060     /**
2061      * @private
2062      * Called when a store is loaded, scrolls to the top row
2063      */
2064     onLoad : function() {
2065         if (Ext.isGecko) {
2066             if (!this.scrollToTopTask) {
2067                 this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
2068             }
2069             this.scrollToTopTask.delay(1);
2070         } else {
2071             this.scrollToTop();
2072         }
2073     },
2074
2075     // private
2076     onColWidthChange : function(cm, col, width) {
2077         this.updateColumnWidth(col, width);
2078     },
2079
2080     // private
2081     onHeaderChange : function(cm, col, text) {
2082         this.updateHeaders();
2083     },
2084
2085     // private
2086     onHiddenChange : function(cm, col, hidden) {
2087         this.updateColumnHidden(col, hidden);
2088     },
2089
2090     // private
2091     onColumnMove : function(cm, oldIndex, newIndex) {
2092         this.indexMap = null;
2093         this.refresh(true);
2094         this.restoreScroll(this.getScrollState());
2095         
2096         this.afterMove(newIndex);
2097         this.grid.fireEvent('columnmove', oldIndex, newIndex);
2098     },
2099
2100     // private
2101     onColConfigChange : function() {
2102         delete this.lastViewWidth;
2103         this.indexMap = null;
2104         this.refresh(true);
2105     },
2106
2107     /* -------------------- UI Events and Handlers ------------------------------ */
2108     // private
2109     initUI : function(grid) {
2110         grid.on('headerclick', this.onHeaderClick, this);
2111     },
2112
2113     // private
2114     initEvents : Ext.emptyFn,
2115
2116     // private
2117     onHeaderClick : function(g, index) {
2118         if (this.headersDisabled || !this.cm.isSortable(index)) {
2119             return;
2120         }
2121         g.stopEditing(true);
2122         g.store.sort(this.cm.getDataIndex(index));
2123     },
2124
2125     /**
2126      * @private
2127      * Adds the hover class to a row when hovered over
2128      */
2129     onRowOver : function(e, target) {
2130         var row = this.findRowIndex(target);
2131         
2132         if (row !== false) {
2133             this.addRowClass(row, this.rowOverCls);
2134         }
2135     },
2136
2137     /**
2138      * @private
2139      * Removes the hover class from a row on mouseout
2140      */
2141     onRowOut : function(e, target) {
2142         var row = this.findRowIndex(target);
2143         
2144         if (row !== false && !e.within(this.getRow(row), true)) {
2145             this.removeRowClass(row, this.rowOverCls);
2146         }
2147     },
2148
2149     // private
2150     onRowSelect : function(row) {
2151         this.addRowClass(row, this.selectedRowClass);
2152     },
2153
2154     // private
2155     onRowDeselect : function(row) {
2156         this.removeRowClass(row, this.selectedRowClass);
2157     },
2158
2159     // private
2160     onCellSelect : function(row, col) {
2161         var cell = this.getCell(row, col);
2162         if (cell) {
2163             this.fly(cell).addClass('x-grid3-cell-selected');
2164         }
2165     },
2166
2167     // private
2168     onCellDeselect : function(row, col) {
2169         var cell = this.getCell(row, col);
2170         if (cell) {
2171             this.fly(cell).removeClass('x-grid3-cell-selected');
2172         }
2173     },
2174
2175     // private
2176     handleWheel : function(e) {
2177         e.stopPropagation();
2178     },
2179
2180     /**
2181      * @private
2182      * Called by the SplitDragZone when a drag has been completed. Resizes the columns
2183      */
2184     onColumnSplitterMoved : function(cellIndex, width) {
2185         this.userResized = true;
2186         this.grid.colModel.setColumnWidth(cellIndex, width, true);
2187
2188         if (this.forceFit) {
2189             this.fitColumns(true, false, cellIndex);
2190             this.updateAllColumnWidths();
2191         } else {
2192             this.updateColumnWidth(cellIndex, width);
2193             this.syncHeaderScroll();
2194         }
2195
2196         this.grid.fireEvent('columnresize', cellIndex, width);
2197     },
2198
2199     /**
2200      * @private
2201      * Click handler for the shared column dropdown menu, called on beforeshow. Builds the menu
2202      * which displays the list of columns for the user to show or hide.
2203      */
2204     beforeColMenuShow : function() {
2205         var colModel = this.cm,
2206             colCount = colModel.getColumnCount(),
2207             colMenu  = this.colMenu,
2208             i;
2209
2210         colMenu.removeAll();
2211
2212         for (i = 0; i < colCount; i++) {
2213             if (colModel.config[i].hideable !== false) {
2214                 colMenu.add(new Ext.menu.CheckItem({
2215                     text       : colModel.getColumnHeader(i),
2216                     itemId     : 'col-' + colModel.getColumnId(i),
2217                     checked    : !colModel.isHidden(i),
2218                     disabled   : colModel.config[i].hideable === false,
2219                     hideOnClick: false
2220                 }));
2221             }
2222         }
2223     },
2224     
2225     /**
2226      * @private
2227      * Attached as the 'itemclick' handler to the header menu and the column show/hide submenu (if available).
2228      * Performs sorting if the sorter buttons were clicked, otherwise hides/shows the column that was clicked.
2229      */
2230     handleHdMenuClick : function(item) {
2231         var store     = this.ds,
2232             dataIndex = this.cm.getDataIndex(this.hdCtxIndex);
2233
2234         switch (item.getItemId()) {
2235             case 'asc':
2236                 store.sort(dataIndex, 'ASC');
2237                 break;
2238             case 'desc':
2239                 store.sort(dataIndex, 'DESC');
2240                 break;
2241             default:
2242                 this.handleHdMenuClickDefault(item);
2243         }
2244         return true;
2245     },
2246     
2247     <div id="method-Ext.grid.GridView-handleHdMenuClickDefault"></div>/**
2248      * Called by handleHdMenuClick if any button except a sort ASC/DESC button was clicked. The default implementation provides
2249      * the column hide/show functionality based on the check state of the menu item. A different implementation can be provided
2250      * if needed.
2251      * @param {Ext.menu.BaseItem} item The menu item that was clicked
2252      */
2253     handleHdMenuClickDefault: function(item) {
2254         var colModel = this.cm,
2255             itemId   = item.getItemId(),
2256             index    = colModel.getIndexById(itemId.substr(4));
2257
2258         if (index != -1) {
2259             if (item.checked && colModel.getColumnsBy(this.isHideableColumn, this).length <= 1) {
2260                 this.onDenyColumnHide();
2261                 return;
2262             }
2263             colModel.setHidden(index, item.checked);
2264         }
2265     },
2266
2267     /**
2268      * @private
2269      * Called when a header cell is clicked - shows the menu if the click happened over a trigger button
2270      */
2271     handleHdDown : function(e, target) {
2272         if (Ext.fly(target).hasClass('x-grid3-hd-btn')) {
2273             e.stopEvent();
2274             
2275             var colModel  = this.cm,
2276                 header    = this.findHeaderCell(target),
2277                 index     = this.getCellIndex(header),
2278                 sortable  = colModel.isSortable(index),
2279                 menu      = this.hmenu,
2280                 menuItems = menu.items,
2281                 menuCls   = this.headerMenuOpenCls;
2282             
2283             this.hdCtxIndex = index;
2284             
2285             Ext.fly(header).addClass(menuCls);
2286             menuItems.get('asc').setDisabled(!sortable);
2287             menuItems.get('desc').setDisabled(!sortable);
2288             
2289             menu.on('hide', function() {
2290                 Ext.fly(header).removeClass(menuCls);
2291             }, this, {single:true});
2292             
2293             menu.show(target, 'tl-bl?');
2294         }
2295     },
2296
2297     /**
2298      * @private
2299      * Attached to the headers' mousemove event. This figures out the CSS cursor to use based on where the mouse is currently
2300      * pointed. If the mouse is currently hovered over the extreme left or extreme right of any header cell and the cell next 
2301      * to it is resizable it is given the resize cursor, otherwise the cursor is set to an empty string.
2302      */
2303     handleHdMove : function(e) {
2304         var header = this.findHeaderCell(this.activeHdRef);
2305         
2306         if (header && !this.headersDisabled) {
2307             var handleWidth  = this.splitHandleWidth || 5,
2308                 activeRegion = this.activeHdRegion,
2309                 headerStyle  = header.style,
2310                 colModel     = this.cm,
2311                 cursor       = '',
2312                 pageX        = e.getPageX();
2313                 
2314             if (this.grid.enableColumnResize !== false) {
2315                 var activeHeaderIndex = this.activeHdIndex,
2316                     previousVisible   = this.getPreviousVisible(activeHeaderIndex),
2317                     currentResizable  = colModel.isResizable(activeHeaderIndex),
2318                     previousResizable = previousVisible && colModel.isResizable(previousVisible),
2319                     inLeftResizer     = pageX - activeRegion.left <= handleWidth,
2320                     inRightResizer    = activeRegion.right - pageX <= (!this.activeHdBtn ? handleWidth : 2);
2321                 
2322                 if (inLeftResizer && previousResizable) {
2323                     cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
2324                 } else if (inRightResizer && currentResizable) {
2325                     cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
2326                 }
2327             }
2328             
2329             headerStyle.cursor = cursor;
2330         }
2331     },
2332     
2333     /**
2334      * @private
2335      * Returns the index of the nearest currently visible header to the left of the given index.
2336      * @param {Number} index The header index
2337      * @return {Number/undefined} The index of the nearest visible header
2338      */
2339     getPreviousVisible: function(index) {
2340         while (index > 0) {
2341             if (!this.cm.isHidden(index - 1)) {
2342                 return index;
2343             }
2344             index--;
2345         }
2346         return undefined;
2347     },
2348
2349     /**
2350      * @private
2351      * Tied to the header element's mouseover event - adds the over class to the header cell if the menu is not disabled
2352      * for that cell
2353      */
2354     handleHdOver : function(e, target) {
2355         var header = this.findHeaderCell(target);
2356         
2357         if (header && !this.headersDisabled) {
2358             var fly = this.fly(header);
2359             
2360             this.activeHdRef = target;
2361             this.activeHdIndex = this.getCellIndex(header);
2362             this.activeHdRegion = fly.getRegion();
2363             
2364             if (!this.isMenuDisabled(this.activeHdIndex, fly)) {
2365                 fly.addClass('x-grid3-hd-over');
2366                 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
2367                 
2368                 if (this.activeHdBtn) {
2369                     this.activeHdBtn.dom.style.height = (header.firstChild.offsetHeight - 1) + 'px';
2370                 }
2371             }
2372         }
2373     },
2374
2375     /**
2376      * @private
2377      * Tied to the header element's mouseout event. Removes the hover class from the header cell
2378      */
2379     handleHdOut : function(e, target) {
2380         var header = this.findHeaderCell(target);
2381         
2382         if (header && (!Ext.isIE || !e.within(header, true))) {
2383             this.activeHdRef = null;
2384             this.fly(header).removeClass('x-grid3-hd-over');
2385             header.style.cursor = '';
2386         }
2387     },
2388     
2389     /**
2390      * @private
2391      * Used by {@link #handleHdOver} to determine whether or not to show the header menu class on cell hover
2392      * @param {Number} cellIndex The header cell index
2393      * @param {Ext.Element} el The cell element currently being hovered over
2394      */
2395     isMenuDisabled: function(cellIndex, el) {
2396         return this.cm.isMenuDisabled(cellIndex);
2397     },
2398
2399     /**
2400      * @private
2401      * Returns true if there are any rows rendered into the GridView
2402      * @return {Boolean} True if any rows have been rendered
2403      */
2404     hasRows : function() {
2405         var fc = this.mainBody.dom.firstChild;
2406         return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
2407     },
2408     
2409     /**
2410      * @private
2411      */
2412     isHideableColumn : function(c) {
2413         return !c.hidden;
2414     },
2415
2416     /**
2417      * @private
2418      * DEPRECATED - will be removed in Ext JS 5.0
2419      */
2420     bind : function(d, c) {
2421         this.initData(d, c);
2422     }
2423 });
2424
2425
2426 // private
2427 // This is a support class used internally by the Grid components
2428 Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
2429
2430     constructor: function(grid, hd){
2431         this.grid = grid;
2432         this.view = grid.getView();
2433         this.marker = this.view.resizeMarker;
2434         this.proxy = this.view.resizeProxy;
2435         Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
2436             'gridSplitters' + this.grid.getGridEl().id, {
2437             dragElId : Ext.id(this.proxy.dom), resizeFrame:false
2438         });
2439         this.scroll = false;
2440         this.hw = this.view.splitHandleWidth || 5;
2441     },
2442
2443     b4StartDrag : function(x, y){
2444         this.dragHeadersDisabled = this.view.headersDisabled;
2445         this.view.headersDisabled = true;
2446         var h = this.view.mainWrap.getHeight();
2447         this.marker.setHeight(h);
2448         this.marker.show();
2449         this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
2450         this.proxy.setHeight(h);
2451         var w = this.cm.getColumnWidth(this.cellIndex),
2452             minw = Math.max(w-this.grid.minColumnWidth, 0);
2453         this.resetConstraints();
2454         this.setXConstraint(minw, 1000);
2455         this.setYConstraint(0, 0);
2456         this.minX = x - minw;
2457         this.maxX = x + 1000;
2458         this.startPos = x;
2459         Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
2460     },
2461
2462     allowHeaderDrag : function(e){
2463         return true;
2464     },
2465
2466     handleMouseDown : function(e){
2467         var t = this.view.findHeaderCell(e.getTarget());
2468         if(t && this.allowHeaderDrag(e)){
2469             var xy = this.view.fly(t).getXY(), 
2470                 x = xy[0],
2471                 exy = e.getXY(), 
2472                 ex = exy[0],
2473                 w = t.offsetWidth, 
2474                 adjust = false;
2475                 
2476             if((ex - x) <= this.hw){
2477                 adjust = -1;
2478             }else if((x+w) - ex <= this.hw){
2479                 adjust = 0;
2480             }
2481             if(adjust !== false){
2482                 this.cm = this.grid.colModel;
2483                 var ci = this.view.getCellIndex(t);
2484                 if(adjust == -1){
2485                   if (ci + adjust < 0) {
2486                     return;
2487                   }
2488                     while(this.cm.isHidden(ci+adjust)){
2489                         --adjust;
2490                         if(ci+adjust < 0){
2491                             return;
2492                         }
2493                     }
2494                 }
2495                 this.cellIndex = ci+adjust;
2496                 this.split = t.dom;
2497                 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
2498                     Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
2499                 }
2500             }else if(this.view.columnDrag){
2501                 this.view.columnDrag.callHandleMouseDown(e);
2502             }
2503         }
2504     },
2505
2506     endDrag : function(e){
2507         this.marker.hide();
2508         var v = this.view,
2509             endX = Math.max(this.minX, e.getPageX()),
2510             diff = endX - this.startPos,
2511             disabled = this.dragHeadersDisabled;
2512             
2513         v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
2514         setTimeout(function(){
2515             v.headersDisabled = disabled;
2516         }, 50);
2517     },
2518
2519     autoOffset : function(){
2520         this.setDelta(0,0);
2521     }
2522 });
2523 </pre>    
2524 </body>
2525 </html>