3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.grid.GridView"></div>/**
10 * @class Ext.grid.GridView
11 * @extends Ext.util.Observable
12 * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
13 * Methods of this class may be used to access user interface elements to enable
14 * special display effects. Do not change the DOM structure of the user interface.</p>
15 * <p>This class does not provide ways to manipulate the underlying data. The data
16 * model of a Grid is held in an {@link Ext.data.Store}.</p>
18 * @param {Object} config
20 Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
21 <div id="method-Ext.grid.GridView-getRowClass"></div>/**
22 * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
23 * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
24 * parameter. This function should return the CSS class name (or empty string '' for none) that will be added
25 * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
26 * (e.g., 'my-class another-class'). Example usage:
30 showPreview: true, // custom property
31 enableRowBody: true, // required to create a second, full-width row to show expanded Record data
32 getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
34 rp.body = '<p>'+record.data.excerpt+'</p>';
35 return 'x-grid3-row-expanded';
37 return 'x-grid3-row-collapsed';
41 * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
42 * @param {Number} index The row index.
43 * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
44 * customization of various aspects of a grid row.
45 * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
46 * by this function, and will be used to render a full-width expansion row below each grid row:</p>
48 * <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>
49 * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's <tr> element. (defaults to '').</div></li>
51 * The following property will be passed in, and may be appended to:
53 * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates
54 * both the standard grid row, and any expansion row.</div></li>
56 * @param {Store} store The {@link Ext.data.Store} this grid is bound to
58 * @return {String} a CSS class name to add to the row.
60 <div id="cfg-Ext.grid.GridView-enableRowBody"></div>/**
61 * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
62 * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
64 <div id="cfg-Ext.grid.GridView-emptyText"></div>/**
65 * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
66 * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
68 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
71 <div id="cfg-Ext.grid.GridView-headersDisabled"></div>/**
72 * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
73 * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
74 * config to disable the <i>menu</i> for individual columns. While this config is true the
75 * following will be disabled:<div class="mdetail-params"><ul>
76 * <li>clicking on header to sort</li>
77 * <li>the trigger to reveal the menu.</li>
80 <div id="prop-Ext.grid.GridView-dragZone"></div>/**
81 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
82 * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
83 * See {@link Ext.grid.GridDragZone} for details.</p>
84 * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>
85 * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>
86 * <li><i>after</i> the owning GridPanel has been rendered.</li>
89 * @type {Ext.grid.GridDragZone}
91 <div id="cfg-Ext.grid.GridView-deferEmptyText"></div>/**
92 * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
93 * first load (defaults to <tt>true</tt>).
95 deferEmptyText : true,
96 <div id="cfg-Ext.grid.GridView-scrollOffset"></div>/**
97 * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
98 * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
101 scrollOffset : undefined,
102 <div id="cfg-Ext.grid.GridView-autoFill"></div>/**
103 * @cfg {Boolean} autoFill
104 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
105 * when the grid is <b>initially rendered</b>. The
106 * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
107 * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
108 * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
109 * See <tt>{@link #forceFit}</tt> also.
112 <div id="cfg-Ext.grid.GridView-forceFit"></div>/**
113 * @cfg {Boolean} forceFit
114 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
115 * at <b>all times</b>. The {@link Ext.grid.Column#width initially configured width}</tt> of each
116 * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are
117 * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized
118 * to fit the grid width. See <tt>{@link #autoFill}</tt> also.
121 <div id="cfg-Ext.grid.GridView-sortClasses"></div>/**
122 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
124 sortClasses : ['sort-asc', 'sort-desc'],
125 <div id="cfg-Ext.grid.GridView-sortAscText"></div>/**
126 * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
128 sortAscText : 'Sort Ascending',
129 <div id="cfg-Ext.grid.GridView-sortDescText"></div>/**
130 * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
132 sortDescText : 'Sort Descending',
133 <div id="cfg-Ext.grid.GridView-columnsText"></div>/**
134 * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>)
136 columnsText : 'Columns',
138 <div id="cfg-Ext.grid.GridView-selectedRowClass"></div>/**
139 * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An
140 * example overriding the default styling:
142 .x-grid3-row-selected {background-color: yellow;}
144 * Note that this only controls the row, and will not do anything for the text inside it. To style inner
145 * facets (like text) use something like:
147 .x-grid3-row-selected .x-grid3-cell-inner {
153 selectedRowClass : 'x-grid3-row-selected',
157 tdClass : 'x-grid3-cell',
158 hdCls : 'x-grid3-hd',
161 <div id="cfg-Ext.grid.GridView-cellSelectorDepth"></div>/**
162 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
164 cellSelectorDepth : 4,
165 <div id="cfg-Ext.grid.GridView-rowSelectorDepth"></div>/**
166 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
168 rowSelectorDepth : 10,
170 <div id="cfg-Ext.grid.GridView-rowBodySelectorDepth"></div>/**
171 * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
173 rowBodySelectorDepth : 10,
175 <div id="cfg-Ext.grid.GridView-cellSelector"></div>/**
176 * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
178 cellSelector : 'td.x-grid3-cell',
179 <div id="cfg-Ext.grid.GridView-rowSelector"></div>/**
180 * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
182 rowSelector : 'div.x-grid3-row',
184 <div id="cfg-Ext.grid.GridView-rowBodySelector"></div>/**
185 * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
187 rowBodySelector : 'div.x-grid3-row-body',
190 firstRowCls: 'x-grid3-row-first',
191 lastRowCls: 'x-grid3-row-last',
192 rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
194 constructor : function(config){
195 Ext.apply(this, config);
196 // These events are only used internally by the grid components
198 <div id="event-Ext.grid.GridView-beforerowremoved"></div>/**
199 * @event beforerowremoved
200 * Internal UI Event. Fired before a row is removed.
201 * @param {Ext.grid.GridView} view
202 * @param {Number} rowIndex The index of the row to be removed.
203 * @param {Ext.data.Record} record The Record to be removed
206 <div id="event-Ext.grid.GridView-beforerowsinserted"></div>/**
207 * @event beforerowsinserted
208 * Internal UI Event. Fired before rows are inserted.
209 * @param {Ext.grid.GridView} view
210 * @param {Number} firstRow The index of the first row to be inserted.
211 * @param {Number} lastRow The index of the last row to be inserted.
213 'beforerowsinserted',
214 <div id="event-Ext.grid.GridView-beforerefresh"></div>/**
215 * @event beforerefresh
216 * Internal UI Event. Fired before the view is refreshed.
217 * @param {Ext.grid.GridView} view
220 <div id="event-Ext.grid.GridView-rowremoved"></div>/**
222 * Internal UI Event. Fired after a row is removed.
223 * @param {Ext.grid.GridView} view
224 * @param {Number} rowIndex The index of the row that was removed.
225 * @param {Ext.data.Record} record The Record that was removed
228 <div id="event-Ext.grid.GridView-rowsinserted"></div>/**
229 * @event rowsinserted
230 * Internal UI Event. Fired after rows are inserted.
231 * @param {Ext.grid.GridView} view
232 * @param {Number} firstRow The index of the first inserted.
233 * @param {Number} lastRow The index of the last row inserted.
236 <div id="event-Ext.grid.GridView-rowupdated"></div>/**
238 * Internal UI Event. Fired after a row has been updated.
239 * @param {Ext.grid.GridView} view
240 * @param {Number} firstRow The index of the row updated.
241 * @param {Ext.data.record} record The Record backing the row updated.
244 <div id="event-Ext.grid.GridView-refresh"></div>/**
246 * Internal UI Event. Fired after the GridView's body has been refreshed.
247 * @param {Ext.grid.GridView} view
251 Ext.grid.GridView.superclass.constructor.call(this);
254 /* -------------------------------- UI Specific ----------------------------- */
257 initTemplates : function(){
258 var ts = this.templates || {};
260 ts.master = new Ext.Template(
261 '<div class="x-grid3" hidefocus="true">',
262 '<div class="x-grid3-viewport">',
263 '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
264 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
266 '<div class="x-grid3-resize-marker"> </div>',
267 '<div class="x-grid3-resize-proxy"> </div>',
273 ts.header = new Ext.Template(
274 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
275 '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
281 ts.hcell = new Ext.Template(
282 '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
283 '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
289 ts.body = new Ext.Template('{rows}');
293 ts.row = new Ext.Template(
294 '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
295 '<tbody><tr>{cells}</tr>',
296 (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
297 '</tbody></table></div>'
302 ts.cell = new Ext.Template(
303 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
304 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
311 if(t && Ext.isFunction(t.compile) && !t.compiled){
312 t.disableFormats = true;
318 this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
323 if(!this._flyweight){
324 this._flyweight = new Ext.Element.Flyweight(document.body);
326 this._flyweight.dom = el;
327 return this._flyweight;
331 getEditorParent : function(){
332 return this.scroller.dom;
336 initElements : function(){
339 var el = this.grid.getGridEl().dom.firstChild;
340 var cs = el.childNodes;
344 this.mainWrap = new E(cs[0]);
345 this.mainHd = new E(this.mainWrap.dom.firstChild);
347 if(this.grid.hideHeaders){
348 this.mainHd.setDisplayed(false);
351 this.innerHd = this.mainHd.dom.firstChild;
352 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
354 this.scroller.setStyle('overflow-x', 'hidden');
356 <div id="prop-Ext.grid.GridView-mainBody"></div>/**
357 * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
358 * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
362 this.mainBody = new E(this.scroller.dom.firstChild);
364 this.focusEl = new E(this.scroller.dom.childNodes[1]);
365 this.focusEl.swallowEvent('click', true);
367 this.resizeMarker = new E(cs[1]);
368 this.resizeProxy = new E(cs[2]);
372 getRows : function(){
373 return this.hasRows() ? this.mainBody.dom.childNodes : [];
376 // finder methods, used with delegation
379 findCell : function(el){
383 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
386 <div id="method-Ext.grid.GridView-findCellIndex"></div>/**
387 * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
388 * See also {@link #findRowIndex}
389 * @param {HTMLElement} el The target element
390 * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
392 findCellIndex : function(el, requiredCls){
393 var cell = this.findCell(el);
394 if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
395 return this.getCellIndex(cell);
401 getCellIndex : function(el){
403 var m = el.className.match(this.colRe);
405 return this.cm.getIndexById(m[1]);
412 findHeaderCell : function(el){
413 var cell = this.findCell(el);
414 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
418 findHeaderIndex : function(el){
419 return this.findCellIndex(el, this.hdCls);
422 <div id="method-Ext.grid.GridView-findRow"></div>/**
423 * Return the HtmlElement representing the grid row which contains the passed element.
424 * @param {HTMLElement} el The target HTMLElement
425 * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
427 findRow : function(el){
431 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
434 <div id="method-Ext.grid.GridView-findRowIndex"></div>/**
435 * <p>Return the index of the grid row which contains the passed HTMLElement.</p>
436 * See also {@link #findCellIndex}
437 * @param {HTMLElement} el The target HTMLElement
438 * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
440 findRowIndex : function(el){
441 var r = this.findRow(el);
442 return r ? r.rowIndex : false;
445 <div id="method-Ext.grid.GridView-findRowBody"></div>/**
446 * Return the HtmlElement representing the grid row body which contains the passed element.
447 * @param {HTMLElement} el The target HTMLElement
448 * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
450 findRowBody : function(el){
454 return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
457 // getter methods for fetching elements dynamically in the grid
459 <div id="method-Ext.grid.GridView-getRow"></div>/**
460 * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
461 * @param {Number} index The row index
462 * @return {HtmlElement} The div element.
464 getRow : function(row){
465 return this.getRows()[row];
468 <div id="method-Ext.grid.GridView-getCell"></div>/**
469 * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
470 * @param {Number} row The row index in which to find the cell.
471 * @param {Number} col The column index of the cell.
472 * @return {HtmlElement} The td at the specified coordinates.
474 getCell : function(row, col){
475 return this.getRow(row).getElementsByTagName('td')[col];
478 <div id="method-Ext.grid.GridView-getHeaderCell"></div>/**
479 * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
480 * @param {Number} index The column index
481 * @return {HtmlElement} The td element.
483 getHeaderCell : function(index){
484 return this.mainHd.dom.getElementsByTagName('td')[index];
487 // manipulating elements
489 // private - use getRowClass to apply custom row classes
490 addRowClass : function(row, cls){
491 var r = this.getRow(row);
493 this.fly(r).addClass(cls);
498 removeRowClass : function(row, cls){
499 var r = this.getRow(row);
501 this.fly(r).removeClass(cls);
506 removeRow : function(row){
507 Ext.removeNode(this.getRow(row));
508 this.syncFocusEl(row);
512 removeRows : function(firstRow, lastRow){
513 var bd = this.mainBody.dom;
514 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
515 Ext.removeNode(bd.childNodes[firstRow]);
517 this.syncFocusEl(firstRow);
523 getScrollState : function(){
524 var sb = this.scroller.dom;
525 return {left: sb.scrollLeft, top: sb.scrollTop};
529 restoreScroll : function(state){
530 var sb = this.scroller.dom;
531 sb.scrollLeft = state.left;
532 sb.scrollTop = state.top;
535 <div id="method-Ext.grid.GridView-scrollToTop"></div>/**
536 * Scrolls the grid to the top
538 scrollToTop : function(){
539 this.scroller.dom.scrollTop = 0;
540 this.scroller.dom.scrollLeft = 0;
544 syncScroll : function(){
545 this.syncHeaderScroll();
546 var mb = this.scroller.dom;
547 this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
551 syncHeaderScroll : function(){
552 var mb = this.scroller.dom;
553 this.innerHd.scrollLeft = mb.scrollLeft;
554 this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
558 updateSortIcon : function(col, dir){
559 var sc = this.sortClasses;
560 var hds = this.mainHd.select('td').removeClass(sc);
561 hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]);
565 updateAllColumnWidths : function(){
566 var tw = this.getTotalWidth(),
567 clen = this.cm.getColumnCount(),
571 for(i = 0; i < clen; i++){
572 ws[i] = this.getColumnWidth(i);
574 this.innerHd.firstChild.style.width = this.getOffsetWidth();
575 this.innerHd.firstChild.firstChild.style.width = tw;
576 this.mainBody.dom.style.width = tw;
577 for(i = 0; i < clen; i++){
578 var hd = this.getHeaderCell(i);
579 hd.style.width = ws[i];
582 var ns = this.getRows(), row, trow;
583 for(i = 0, len = ns.length; i < len; i++){
585 row.style.width = tw;
587 row.firstChild.style.width = tw;
588 trow = row.firstChild.rows[0];
589 for (var j = 0; j < clen; j++) {
590 trow.childNodes[j].style.width = ws[j];
595 this.onAllColumnWidthsUpdated(ws, tw);
599 updateColumnWidth : function(col, width){
600 var w = this.getColumnWidth(col);
601 var tw = this.getTotalWidth();
602 this.innerHd.firstChild.style.width = this.getOffsetWidth();
603 this.innerHd.firstChild.firstChild.style.width = tw;
604 this.mainBody.dom.style.width = tw;
605 var hd = this.getHeaderCell(col);
608 var ns = this.getRows(), row;
609 for(var i = 0, len = ns.length; i < len; i++){
611 row.style.width = tw;
613 row.firstChild.style.width = tw;
614 row.firstChild.rows[0].childNodes[col].style.width = w;
618 this.onColumnWidthUpdated(col, w, tw);
622 updateColumnHidden : function(col, hidden){
623 var tw = this.getTotalWidth();
624 this.innerHd.firstChild.style.width = this.getOffsetWidth();
625 this.innerHd.firstChild.firstChild.style.width = tw;
626 this.mainBody.dom.style.width = tw;
627 var display = hidden ? 'none' : '';
629 var hd = this.getHeaderCell(col);
630 hd.style.display = display;
632 var ns = this.getRows(), row;
633 for(var i = 0, len = ns.length; i < len; i++){
635 row.style.width = tw;
637 row.firstChild.style.width = tw;
638 row.firstChild.rows[0].childNodes[col].style.display = display;
642 this.onColumnHiddenUpdated(col, hidden, tw);
643 delete this.lastViewWidth; // force recalc
648 doRender : function(cs, rs, ds, startRow, colCount, stripe){
649 var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
650 var tstyle = 'width:'+this.getTotalWidth()+';';
652 var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
653 for(var j = 0, len = rs.length; j < len; j++){
655 var rowIndex = (j+startRow);
656 for(var i = 0; i < colCount; i++){
659 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
660 p.attr = p.cellAttr = '';
661 p.value = c.renderer.call(c.scope, r.data[c.name], p, r, rowIndex, i, ds);
663 if(Ext.isEmpty(p.value)){
666 if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
667 p.css += ' x-grid3-dirty-cell';
669 cb[cb.length] = ct.apply(p);
672 if(stripe && ((rowIndex+1) % 2 === 0)){
673 alt[0] = 'x-grid3-row-alt';
676 alt[1] = ' x-grid3-dirty-row';
679 if(this.getRowClass){
680 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
682 rp.alt = alt.join(' ');
683 rp.cells = cb.join('');
684 buf[buf.length] = rt.apply(rp);
690 processRows : function(startRow, skipStripe){
691 if(!this.ds || this.ds.getCount() < 1){
694 var rows = this.getRows(),
698 skipStripe = skipStripe || !this.grid.stripeRows;
699 startRow = startRow || 0;
700 for(i = 0; i<len; i++) {
705 r.className = r.className.replace(this.rowClsRe, ' ');
706 if ((i + 1) % 2 === 0){
707 r.className += ' x-grid3-row-alt';
712 // add first/last-row classes
714 Ext.fly(rows[0]).addClass(this.firstRowCls);
716 Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
719 afterRender : function(){
720 if(!this.ds || !this.cm){
723 this.mainBody.dom.innerHTML = this.renderRows() || ' ';
724 this.processRows(0, true);
726 if(this.deferEmptyText !== true){
727 this.applyEmptyText();
729 this.grid.fireEvent('viewready', this.grid);
733 renderUI : function(){
735 var header = this.renderHeaders();
736 var body = this.templates.body.apply({rows:' '});
739 var html = this.templates.master.apply({
742 ostyle: 'width:'+this.getOffsetWidth()+';',
743 bstyle: 'width:'+this.getTotalWidth()+';'
748 g.getGridEl().dom.innerHTML = html;
752 // get mousedowns early
753 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
756 mouseover: this.handleHdOver,
757 mouseout: this.handleHdOut,
758 mousemove: this.handleHdMove
761 this.scroller.on('scroll', this.syncScroll, this);
762 if(g.enableColumnResize !== false){
763 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
766 if(g.enableColumnMove){
767 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
768 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
771 if(g.enableHdMenu !== false){
772 this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
774 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
775 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
777 if(g.enableColumnHide !== false){
778 this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
781 beforeshow: this.beforeColMenuShow,
782 itemclick: this.handleHdMenuClick
784 this.hmenu.add('-', {
787 text: this.columnsText,
789 iconCls: 'x-cols-icon'
792 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
795 if(g.trackMouseOver){
798 mouseover: this.onRowOver,
799 mouseout: this.onRowOut
803 if(g.enableDragDrop || g.enableDrag){
804 this.dragZone = new Ext.grid.GridDragZone(g, {
805 ddGroup : g.ddGroup || 'GridDD'
809 this.updateHeaderSortState();
814 processEvent: Ext.emptyFn,
819 return; // not rendered
822 var c = g.getGridEl();
823 var csize = c.getSize(true);
824 var vw = csize.width;
826 if(!g.hideHeaders && (vw < 20 || csize.height < 20)){ // display: none?
831 this.scroller.dom.style.overflow = 'visible';
833 this.scroller.dom.style.position = 'static';
836 this.el.setSize(csize.width, csize.height);
838 var hdHeight = this.mainHd.getHeight();
839 var vh = csize.height - (hdHeight);
841 this.scroller.setSize(vw, vh);
843 this.innerHd.style.width = (vw)+'px';
847 if(this.lastViewWidth != vw){
848 this.fitColumns(false, false);
849 this.lastViewWidth = vw;
853 this.syncHeaderScroll();
855 this.onLayout(vw, vh);
858 // template functions for subclasses and plugins
859 // these functions include precalculated values
860 onLayout : function(vw, vh){
864 onColumnWidthUpdated : function(col, w, tw){
868 onAllColumnWidthsUpdated : function(ws, tw){
872 onColumnHiddenUpdated : function(col, hidden, tw){
876 updateColumnText : function(col, text){
880 afterMove : function(colIndex){
884 /* ----------------------------------- Core Specific -------------------------------------------*/
886 init : function(grid){
889 this.initTemplates();
890 this.initData(grid.store, grid.colModel);
895 getColumnId : function(index){
896 return this.cm.getColumnId(index);
900 getOffsetWidth : function() {
901 return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
904 getScrollOffset: function(){
905 return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
909 renderHeaders : function(){
915 len = cm.getColumnCount(),
918 for(var i = 0; i < len; i++){
919 p.id = cm.getColumnId(i);
920 p.value = cm.getColumnHeader(i) || '';
921 p.style = this.getColumnStyle(i, true);
922 p.tooltip = this.getColumnTooltip(i);
923 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
924 if(cm.config[i].align == 'right'){
925 p.istyle = 'padding-right:16px';
929 cb[cb.length] = ct.apply(p);
931 return ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'});
935 getColumnTooltip : function(i){
936 var tt = this.cm.getColumnTooltip(i);
938 if(Ext.QuickTips.isEnabled()){
939 return 'ext:qtip="'+tt+'"';
941 return 'title="'+tt+'"';
948 beforeUpdate : function(){
949 this.grid.stopEditing(true);
953 updateHeaders : function(){
954 this.innerHd.firstChild.innerHTML = this.renderHeaders();
955 this.innerHd.firstChild.style.width = this.getOffsetWidth();
956 this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
959 <div id="method-Ext.grid.GridView-focusRow"></div>/**
960 * Focuses the specified row.
961 * @param {Number} row The row index
963 focusRow : function(row){
964 this.focusCell(row, 0, false);
967 <div id="method-Ext.grid.GridView-focusCell"></div>/**
968 * Focuses the specified cell.
969 * @param {Number} row The row index
970 * @param {Number} col The column index
972 focusCell : function(row, col, hscroll){
973 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
975 this.focusEl.focus();
977 this.focusEl.focus.defer(1, this.focusEl);
981 resolveCell : function(row, col, hscroll){
982 if(!Ext.isNumber(row)){
988 if(row < 0 || row >= this.ds.getCount()){
991 col = (col !== undefined ? col : 0);
993 var rowEl = this.getRow(row),
995 colCount = cm.getColumnCount(),
997 if(!(hscroll === false && col === 0)){
998 while(col < colCount && cm.isHidden(col)){
1001 cellEl = this.getCell(row, col);
1004 return {row: rowEl, cell: cellEl};
1007 getResolvedXY : function(resolved){
1011 var s = this.scroller.dom, c = resolved.cell, r = resolved.row;
1012 return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()];
1015 syncFocusEl : function(row, col, hscroll){
1017 if(!Ext.isArray(xy)){
1018 row = Math.min(row, Math.max(0, this.getRows().length-1));
1019 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
1021 this.focusEl.setXY(xy||this.scroller.getXY());
1024 ensureVisible : function(row, col, hscroll){
1025 var resolved = this.resolveCell(row, col, hscroll);
1026 if(!resolved || !resolved.row){
1030 var rowEl = resolved.row,
1031 cellEl = resolved.cell,
1032 c = this.scroller.dom,
1037 while(p && p != stop){
1038 ctop += p.offsetTop;
1042 ctop -= this.mainHd.dom.offsetHeight;
1043 stop = parseInt(c.scrollTop, 10);
1045 var cbot = ctop + rowEl.offsetHeight,
1046 ch = c.clientHeight,
1052 }else if(cbot > sbot){
1053 c.scrollTop = cbot-ch;
1056 if(hscroll !== false){
1057 var cleft = parseInt(cellEl.offsetLeft, 10);
1058 var cright = cleft + cellEl.offsetWidth;
1060 var sleft = parseInt(c.scrollLeft, 10);
1061 var sright = sleft + c.clientWidth;
1063 c.scrollLeft = cleft;
1064 }else if(cright > sright){
1065 c.scrollLeft = cright-c.clientWidth;
1068 return this.getResolvedXY(resolved);
1072 insertRows : function(dm, firstRow, lastRow, isUpdate){
1073 var last = dm.getCount() - 1;
1074 if(!isUpdate && firstRow === 0 && lastRow >= last){
1075 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1077 this.fireEvent('rowsinserted', this, firstRow, lastRow);
1080 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1082 var html = this.renderRows(firstRow, lastRow),
1083 before = this.getRow(firstRow);
1086 Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
1088 Ext.DomHelper.insertHtml('beforeBegin', before, html);
1090 var r = this.getRow(last - 1);
1092 Ext.fly(r).removeClass(this.lastRowCls);
1094 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
1097 this.fireEvent('rowsinserted', this, firstRow, lastRow);
1098 this.processRows(firstRow);
1099 }else if(firstRow === 0 || firstRow >= last){
1100 //ensure first/last row is kept after an update.
1101 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
1104 this.syncFocusEl(firstRow);
1108 deleteRows : function(dm, firstRow, lastRow){
1109 if(dm.getRowCount()<1){
1112 this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
1114 this.removeRows(firstRow, lastRow);
1116 this.processRows(firstRow);
1117 this.fireEvent('rowsdeleted', this, firstRow, lastRow);
1122 getColumnStyle : function(col, isHeader){
1123 var style = !isHeader ? (this.cm.config[col].css || '') : '';
1124 style += 'width:'+this.getColumnWidth(col)+';';
1125 if(this.cm.isHidden(col)){
1126 style += 'display:none;';
1128 var align = this.cm.config[col].align;
1130 style += 'text-align:'+align+';';
1136 getColumnWidth : function(col){
1137 var w = this.cm.getColumnWidth(col);
1138 if(Ext.isNumber(w)){
1139 return (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? w : (w - this.borderWidth > 0 ? w - this.borderWidth : 0)) + 'px';
1145 getTotalWidth : function(){
1146 return this.cm.getTotalWidth()+'px';
1150 fitColumns : function(preventRefresh, onlyExpand, omitColumn){
1151 var cm = this.cm, i;
1152 var tw = cm.getTotalWidth(false);
1153 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
1155 if(aw < 20){ // not initialized, so don't screw up the default widths
1158 var extra = aw - tw;
1164 var vc = cm.getColumnCount(true);
1165 var ac = vc-(Ext.isNumber(omitColumn) ? 1 : 0);
1168 omitColumn = undefined;
1170 var colCount = cm.getColumnCount();
1175 for (i = 0; i < colCount; i++){
1176 if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
1177 w = cm.getColumnWidth(i);
1184 var frac = (aw - cm.getTotalWidth())/width;
1185 while (cols.length){
1188 cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
1191 if((tw = cm.getTotalWidth(false)) > aw){
1192 var adjustCol = ac != vc ? omitColumn : extraCol;
1193 cm.setColumnWidth(adjustCol, Math.max(1,
1194 cm.getColumnWidth(adjustCol)- (tw-aw)), true);
1197 if(preventRefresh !== true){
1198 this.updateAllColumnWidths();
1206 autoExpand : function(preventUpdate){
1207 var g = this.grid, cm = this.cm;
1208 if(!this.userResized && g.autoExpandColumn){
1209 var tw = cm.getTotalWidth(false);
1210 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
1212 var ci = cm.getIndexById(g.autoExpandColumn);
1213 var currentWidth = cm.getColumnWidth(ci);
1214 var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
1215 if(cw != currentWidth){
1216 cm.setColumnWidth(ci, cw, true);
1217 if(preventUpdate !== true){
1218 this.updateColumnWidth(ci, cw);
1226 getColumnData : function(){
1227 // build a map for all the columns
1228 var cs = [], cm = this.cm, colCount = cm.getColumnCount();
1229 for(var i = 0; i < colCount; i++){
1230 var name = cm.getDataIndex(i);
1232 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
1233 renderer : cm.getRenderer(i),
1234 scope: cm.getRendererScope(i),
1235 id : cm.getColumnId(i),
1236 style : this.getColumnStyle(i)
1243 renderRows : function(startRow, endRow){
1244 // pull in all the crap needed to render rows
1245 var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
1246 var colCount = cm.getColumnCount();
1248 if(ds.getCount() < 1){
1252 var cs = this.getColumnData();
1254 startRow = startRow || 0;
1255 endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow;
1257 // records to render
1258 var rs = ds.getRange(startRow, endRow);
1260 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
1264 renderBody : function(){
1265 var markup = this.renderRows() || ' ';
1266 return this.templates.body.apply({rows: markup});
1270 refreshRow : function(record){
1271 var ds = this.ds, index;
1272 if(Ext.isNumber(record)){
1274 record = ds.getAt(index);
1279 index = ds.indexOf(record);
1284 this.insertRows(ds, index, index, true);
1285 this.getRow(index).rowIndex = index;
1286 this.onRemove(ds, record, index+1, true);
1287 this.fireEvent('rowupdated', this, index, record);
1290 <div id="method-Ext.grid.GridView-refresh"></div>/**
1291 * Refreshs the grid UI
1292 * @param {Boolean} headersToo (optional) True to also refresh the headers
1294 refresh : function(headersToo){
1295 this.fireEvent('beforerefresh', this);
1296 this.grid.stopEditing(true);
1298 var result = this.renderBody();
1299 this.mainBody.update(result).setWidth(this.getTotalWidth());
1300 if(headersToo === true){
1301 this.updateHeaders();
1302 this.updateHeaderSortState();
1304 this.processRows(0, true);
1306 this.applyEmptyText();
1307 this.fireEvent('refresh', this);
1311 applyEmptyText : function(){
1312 if(this.emptyText && !this.hasRows()){
1313 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1318 updateHeaderSortState : function(){
1319 var state = this.ds.getSortState();
1323 if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){
1324 this.grid.fireEvent('sortchange', this.grid, state);
1326 this.sortState = state;
1327 var sortColumn = this.cm.findColumnIndex(state.field);
1328 if(sortColumn != -1){
1329 var sortDir = state.direction;
1330 this.updateSortIcon(sortColumn, sortDir);
1335 clearHeaderSortState : function(){
1336 if(!this.sortState){
1339 this.grid.fireEvent('sortchange', this.grid, null);
1340 this.mainHd.select('td').removeClass(this.sortClasses);
1341 delete this.sortState;
1345 destroy : function(){
1347 Ext.menu.MenuMgr.unregister(this.colMenu);
1348 this.colMenu.destroy();
1349 delete this.colMenu;
1352 Ext.menu.MenuMgr.unregister(this.hmenu);
1353 this.hmenu.destroy();
1357 this.initData(null, null);
1358 this.purgeListeners();
1359 Ext.fly(this.innerHd).un("click", this.handleHdDown, this);
1361 if(this.grid.enableColumnMove){
1364 this.columnDrag.proxy.ghost,
1365 this.columnDrag.proxy.el,
1367 this.columnDrop.proxyTop,
1368 this.columnDrop.proxyBottom,
1369 this.columnDrag.dragData.ddel,
1370 this.columnDrag.dragData.header
1372 if (this.columnDrag.proxy.anim) {
1373 Ext.destroy(this.columnDrag.proxy.anim);
1375 delete this.columnDrag.proxy.ghost;
1376 delete this.columnDrag.dragData.ddel;
1377 delete this.columnDrag.dragData.header;
1378 this.columnDrag.destroy();
1379 delete Ext.dd.DDM.locationCache[this.columnDrag.id];
1380 delete this.columnDrag._domRef;
1382 delete this.columnDrop.proxyTop;
1383 delete this.columnDrop.proxyBottom;
1384 this.columnDrop.destroy();
1385 delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id];
1386 delete this.columnDrop._domRef;
1387 delete Ext.dd.DDM.ids[this.columnDrop.ddGroup];
1390 if (this.splitZone){ // enableColumnResize
1391 this.splitZone.destroy();
1392 delete this.splitZone._domRef;
1393 delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id];
1396 Ext.fly(this.innerHd).removeAllListeners();
1397 Ext.removeNode(this.innerHd);
1398 delete this.innerHd;
1415 delete this.grid.container;
1418 this.dragZone.destroy();
1421 Ext.dd.DDM.currentTarget = null;
1422 delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id];
1424 Ext.EventManager.removeResizeListener(this.onWindowResize, this);
1428 onDenyColumnHide : function(){
1433 render : function(){
1435 var ct = this.grid.ownerCt;
1436 if (ct && ct.getLayout()){
1437 ct.on('afterlayout', function(){
1438 this.fitColumns(true, true);
1439 this.updateHeaders();
1440 }, this, {single: true});
1442 this.fitColumns(true, true);
1444 }else if(this.forceFit){
1445 this.fitColumns(true, false);
1446 }else if(this.grid.autoExpandColumn){
1447 this.autoExpand(true);
1453 /* --------------------------------- Model Events and Handlers --------------------------------*/
1455 initData : function(ds, cm){
1457 this.ds.un('load', this.onLoad, this);
1458 this.ds.un('datachanged', this.onDataChange, this);
1459 this.ds.un('add', this.onAdd, this);
1460 this.ds.un('remove', this.onRemove, this);
1461 this.ds.un('update', this.onUpdate, this);
1462 this.ds.un('clear', this.onClear, this);
1463 if(this.ds !== ds && this.ds.autoDestroy){
1471 datachanged: this.onDataChange,
1473 remove: this.onRemove,
1474 update: this.onUpdate,
1481 this.cm.un('configchange', this.onColConfigChange, this);
1482 this.cm.un('widthchange', this.onColWidthChange, this);
1483 this.cm.un('headerchange', this.onHeaderChange, this);
1484 this.cm.un('hiddenchange', this.onHiddenChange, this);
1485 this.cm.un('columnmoved', this.onColumnMove, this);
1488 delete this.lastViewWidth;
1491 configchange: this.onColConfigChange,
1492 widthchange: this.onColWidthChange,
1493 headerchange: this.onHeaderChange,
1494 hiddenchange: this.onHiddenChange,
1495 columnmoved: this.onColumnMove
1502 onDataChange : function(){
1504 this.updateHeaderSortState();
1505 this.syncFocusEl(0);
1509 onClear : function(){
1511 this.syncFocusEl(0);
1515 onUpdate : function(ds, record){
1516 this.refreshRow(record);
1520 onAdd : function(ds, records, index){
1522 this.insertRows(ds, index, index + (records.length-1));
1526 onRemove : function(ds, record, index, isUpdate){
1527 if(isUpdate !== true){
1528 this.fireEvent('beforerowremoved', this, index, record);
1530 this.removeRow(index);
1531 if(isUpdate !== true){
1532 this.processRows(index);
1533 this.applyEmptyText();
1534 this.fireEvent('rowremoved', this, index, record);
1539 onLoad : function(){
1540 this.scrollToTop.defer(Ext.isGecko ? 1 : 0, this);
1544 onColWidthChange : function(cm, col, width){
1545 this.updateColumnWidth(col, width);
1549 onHeaderChange : function(cm, col, text){
1550 this.updateHeaders();
1554 onHiddenChange : function(cm, col, hidden){
1555 this.updateColumnHidden(col, hidden);
1559 onColumnMove : function(cm, oldIndex, newIndex){
1560 this.indexMap = null;
1561 var s = this.getScrollState();
1563 this.restoreScroll(s);
1564 this.afterMove(newIndex);
1565 this.grid.fireEvent('columnmove', oldIndex, newIndex);
1569 onColConfigChange : function(){
1570 delete this.lastViewWidth;
1571 this.indexMap = null;
1575 /* -------------------- UI Events and Handlers ------------------------------ */
1577 initUI : function(grid){
1578 grid.on('headerclick', this.onHeaderClick, this);
1582 initEvents : function(){
1586 onHeaderClick : function(g, index){
1587 if(this.headersDisabled || !this.cm.isSortable(index)){
1590 g.stopEditing(true);
1591 g.store.sort(this.cm.getDataIndex(index));
1595 onRowOver : function(e, t){
1597 if((row = this.findRowIndex(t)) !== false){
1598 this.addRowClass(row, 'x-grid3-row-over');
1603 onRowOut : function(e, t){
1605 if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
1606 this.removeRowClass(row, 'x-grid3-row-over');
1611 handleWheel : function(e){
1612 e.stopPropagation();
1616 onRowSelect : function(row){
1617 this.addRowClass(row, this.selectedRowClass);
1621 onRowDeselect : function(row){
1622 this.removeRowClass(row, this.selectedRowClass);
1626 onCellSelect : function(row, col){
1627 var cell = this.getCell(row, col);
1629 this.fly(cell).addClass('x-grid3-cell-selected');
1634 onCellDeselect : function(row, col){
1635 var cell = this.getCell(row, col);
1637 this.fly(cell).removeClass('x-grid3-cell-selected');
1642 onColumnSplitterMoved : function(i, w){
1643 this.userResized = true;
1644 var cm = this.grid.colModel;
1645 cm.setColumnWidth(i, w, true);
1648 this.fitColumns(true, false, i);
1649 this.updateAllColumnWidths();
1651 this.updateColumnWidth(i, w);
1652 this.syncHeaderScroll();
1655 this.grid.fireEvent('columnresize', i, w);
1659 handleHdMenuClick : function(item){
1660 var index = this.hdCtxIndex,
1663 id = item.getItemId();
1666 ds.sort(cm.getDataIndex(index), 'ASC');
1669 ds.sort(cm.getDataIndex(index), 'DESC');
1672 index = cm.getIndexById(id.substr(4));
1674 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
1675 this.onDenyColumnHide();
1678 cm.setHidden(index, item.checked);
1685 isHideableColumn : function(c){
1686 return !c.hidden && !c.fixed;
1690 beforeColMenuShow : function(){
1691 var cm = this.cm, colCount = cm.getColumnCount();
1692 this.colMenu.removeAll();
1693 for(var i = 0; i < colCount; i++){
1694 if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
1695 this.colMenu.add(new Ext.menu.CheckItem({
1696 itemId: 'col-'+cm.getColumnId(i),
1697 text: cm.getColumnHeader(i),
1698 checked: !cm.isHidden(i),
1700 disabled: cm.config[i].hideable === false
1707 handleHdDown : function(e, t){
1708 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
1710 var hd = this.findHeaderCell(t);
1711 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
1712 var index = this.getCellIndex(hd);
1713 this.hdCtxIndex = index;
1714 var ms = this.hmenu.items, cm = this.cm;
1715 ms.get('asc').setDisabled(!cm.isSortable(index));
1716 ms.get('desc').setDisabled(!cm.isSortable(index));
1717 this.hmenu.on('hide', function(){
1718 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
1719 }, this, {single:true});
1720 this.hmenu.show(t, 'tl-bl?');
1725 handleHdOver : function(e, t){
1726 var hd = this.findHeaderCell(t);
1727 if(hd && !this.headersDisabled){
1728 this.activeHdRef = t;
1729 this.activeHdIndex = this.getCellIndex(hd);
1730 var fly = this.fly(hd);
1731 this.activeHdRegion = fly.getRegion();
1732 if(!this.cm.isMenuDisabled(this.activeHdIndex)){
1733 fly.addClass('x-grid3-hd-over');
1734 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
1735 if(this.activeHdBtn){
1736 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
1743 handleHdMove : function(e, t){
1744 var hd = this.findHeaderCell(this.activeHdRef);
1745 if(hd && !this.headersDisabled){
1746 var hw = this.splitHandleWidth || 5,
1747 r = this.activeHdRegion,
1751 if(this.grid.enableColumnResize !== false){
1752 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
1753 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
1754 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
1755 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
1763 handleHdOut : function(e, t){
1764 var hd = this.findHeaderCell(t);
1765 if(hd && (!Ext.isIE || !e.within(hd, true))){
1766 this.activeHdRef = null;
1767 this.fly(hd).removeClass('x-grid3-hd-over');
1768 hd.style.cursor = '';
1773 hasRows : function(){
1774 var fc = this.mainBody.dom.firstChild;
1775 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
1779 bind : function(d, c){
1780 this.initData(d, c);
1786 // This is a support class used internally by the Grid components
1787 Ext.grid.GridView.SplitDragZone = function(grid, hd){
1789 this.view = grid.getView();
1790 this.marker = this.view.resizeMarker;
1791 this.proxy = this.view.resizeProxy;
1792 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
1793 'gridSplitters' + this.grid.getGridEl().id, {
1794 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
1796 this.scroll = false;
1797 this.hw = this.view.splitHandleWidth || 5;
1799 Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, {
1801 b4StartDrag : function(x, y){
1802 this.view.headersDisabled = true;
1803 var h = this.view.mainWrap.getHeight();
1804 this.marker.setHeight(h);
1806 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
1807 this.proxy.setHeight(h);
1808 var w = this.cm.getColumnWidth(this.cellIndex);
1809 var minw = Math.max(w-this.grid.minColumnWidth, 0);
1810 this.resetConstraints();
1811 this.setXConstraint(minw, 1000);
1812 this.setYConstraint(0, 0);
1813 this.minX = x - minw;
1814 this.maxX = x + 1000;
1816 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
1819 allowHeaderDrag : function(e){
1824 handleMouseDown : function(e){
1825 var t = this.view.findHeaderCell(e.getTarget());
1826 if(t && this.allowHeaderDrag(e)){
1827 var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1];
1828 var exy = e.getXY(), ex = exy[0];
1829 var w = t.offsetWidth, adjust = false;
1830 if((ex - x) <= this.hw){
1832 }else if((x+w) - ex <= this.hw){
1835 if(adjust !== false){
1836 this.cm = this.grid.colModel;
1837 var ci = this.view.getCellIndex(t);
1839 if (ci + adjust < 0) {
1842 while(this.cm.isHidden(ci+adjust)){
1849 this.cellIndex = ci+adjust;
1851 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
1852 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
1854 }else if(this.view.columnDrag){
1855 this.view.columnDrag.callHandleMouseDown(e);
1860 endDrag : function(e){
1863 var endX = Math.max(this.minX, e.getPageX());
1864 var diff = endX - this.startPos;
1865 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
1866 setTimeout(function(){
1867 v.headersDisabled = false;
1871 autoOffset : function(){