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>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
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>
24 * @param {Object} config
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:
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
40 rp.body = '<p>'+record.data.excerpt+'</p>';
41 return 'x-grid3-row-expanded';
43 return 'x-grid3-row-collapsed';
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>
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 <tr> element. (defaults to '').</div></li>
57 * The following property will be passed in, and may be appended to:
59 * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates
60 * both the standard grid row, and any expansion row.</div></li>
62 * @param {Store} store The {@link Ext.data.Store} this grid is bound to
64 * @return {String} a CSS class name to add to the row.
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.
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>:
76 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
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>
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>
99 * @type {Ext.grid.GridDragZone}
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>).
106 deferEmptyText : true,
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
113 scrollOffset : undefined,
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.
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.
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>)
139 sortClasses : ['sort-asc', 'sort-desc'],
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>)
144 sortAscText : 'Sort Ascending',
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>)
149 sortDescText : 'Sort Descending',
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>)
154 columnsText : 'Columns',
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:
160 .x-grid3-row-selected {background-color: yellow;}
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:
165 .x-grid3-row-selected .x-grid3-cell-inner {
171 selectedRowClass : 'x-grid3-row-selected',
175 tdClass : 'x-grid3-cell',
176 hdCls : 'x-grid3-hd',
179 <div id="cfg-Ext.grid.GridView-cellSelectorDepth"></div>/**
180 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
182 cellSelectorDepth : 4,
183 <div id="cfg-Ext.grid.GridView-rowSelectorDepth"></div>/**
184 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
186 rowSelectorDepth : 10,
188 <div id="cfg-Ext.grid.GridView-rowBodySelectorDepth"></div>/**
189 * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
191 rowBodySelectorDepth : 10,
193 <div id="cfg-Ext.grid.GridView-cellSelector"></div>/**
194 * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
196 cellSelector : 'td.x-grid3-cell',
197 <div id="cfg-Ext.grid.GridView-rowSelector"></div>/**
198 * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
200 rowSelector : 'div.x-grid3-row',
202 <div id="cfg-Ext.grid.GridView-rowBodySelector"></div>/**
203 * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
205 rowBodySelector : 'div.x-grid3-row-body',
208 firstRowCls: 'x-grid3-row-first',
209 lastRowCls: 'x-grid3-row-last',
210 rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
212 constructor : function(config){
213 Ext.apply(this, config);
214 // These events are only used internally by the grid components
216 <div id="event-Ext.grid.GridView-beforerowremoved"></div>/**
217 * @event beforerowremoved
218 * Internal UI Event. Fired before a row is removed.
219 * @param {Ext.grid.GridView} view
220 * @param {Number} rowIndex The index of the row to be removed.
221 * @param {Ext.data.Record} record The Record to be removed
224 <div id="event-Ext.grid.GridView-beforerowsinserted"></div>/**
225 * @event beforerowsinserted
226 * Internal UI Event. Fired before rows are inserted.
227 * @param {Ext.grid.GridView} view
228 * @param {Number} firstRow The index of the first row to be inserted.
229 * @param {Number} lastRow The index of the last row to be inserted.
231 'beforerowsinserted',
232 <div id="event-Ext.grid.GridView-beforerefresh"></div>/**
233 * @event beforerefresh
234 * Internal UI Event. Fired before the view is refreshed.
235 * @param {Ext.grid.GridView} view
238 <div id="event-Ext.grid.GridView-rowremoved"></div>/**
240 * Internal UI Event. Fired after a row is removed.
241 * @param {Ext.grid.GridView} view
242 * @param {Number} rowIndex The index of the row that was removed.
243 * @param {Ext.data.Record} record The Record that was removed
246 <div id="event-Ext.grid.GridView-rowsinserted"></div>/**
247 * @event rowsinserted
248 * Internal UI Event. Fired after rows are inserted.
249 * @param {Ext.grid.GridView} view
250 * @param {Number} firstRow The index of the first inserted.
251 * @param {Number} lastRow The index of the last row inserted.
254 <div id="event-Ext.grid.GridView-rowupdated"></div>/**
256 * Internal UI Event. Fired after a row has been updated.
257 * @param {Ext.grid.GridView} view
258 * @param {Number} firstRow The index of the row updated.
259 * @param {Ext.data.record} record The Record backing the row updated.
262 <div id="event-Ext.grid.GridView-refresh"></div>/**
264 * Internal UI Event. Fired after the GridView's body has been refreshed.
265 * @param {Ext.grid.GridView} view
269 Ext.grid.GridView.superclass.constructor.call(this);
272 /* -------------------------------- UI Specific ----------------------------- */
275 initTemplates : function(){
276 var ts = this.templates || {};
278 ts.master = new Ext.Template(
279 '<div class="x-grid3" hidefocus="true">',
280 '<div class="x-grid3-viewport">',
281 '<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>',
282 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
284 '<div class="x-grid3-resize-marker"> </div>',
285 '<div class="x-grid3-resize-proxy"> </div>',
291 ts.header = new Ext.Template(
292 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
293 '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
299 ts.hcell = new Ext.Template(
300 '<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>' : '',
301 '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
307 ts.body = new Ext.Template('{rows}');
311 ts.row = new Ext.Template(
312 '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
313 '<tbody><tr>{cells}</tr>',
314 (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>' : ''),
315 '</tbody></table></div>'
320 ts.cell = new Ext.Template(
321 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
322 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
329 if(t && Ext.isFunction(t.compile) && !t.compiled){
330 t.disableFormats = true;
336 this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
341 if(!this._flyweight){
342 this._flyweight = new Ext.Element.Flyweight(document.body);
344 this._flyweight.dom = el;
345 return this._flyweight;
349 getEditorParent : function(){
350 return this.scroller.dom;
354 initElements : function(){
357 var el = this.grid.getGridEl().dom.firstChild;
358 var cs = el.childNodes;
362 this.mainWrap = new E(cs[0]);
363 this.mainHd = new E(this.mainWrap.dom.firstChild);
365 if(this.grid.hideHeaders){
366 this.mainHd.setDisplayed(false);
369 this.innerHd = this.mainHd.dom.firstChild;
370 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
372 this.scroller.setStyle('overflow-x', 'hidden');
374 <div id="prop-Ext.grid.GridView-mainBody"></div>/**
375 * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
376 * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
380 this.mainBody = new E(this.scroller.dom.firstChild);
382 this.focusEl = new E(this.scroller.dom.childNodes[1]);
383 this.focusEl.swallowEvent('click', true);
385 this.resizeMarker = new E(cs[1]);
386 this.resizeProxy = new E(cs[2]);
390 getRows : function(){
391 return this.hasRows() ? this.mainBody.dom.childNodes : [];
394 // finder methods, used with delegation
397 findCell : function(el){
401 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
404 <div id="method-Ext.grid.GridView-findCellIndex"></div>/**
405 * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
406 * See also {@link #findRowIndex}
407 * @param {HTMLElement} el The target element
408 * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
410 findCellIndex : function(el, requiredCls){
411 var cell = this.findCell(el);
412 if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
413 return this.getCellIndex(cell);
419 getCellIndex : function(el){
421 var m = el.className.match(this.colRe);
423 return this.cm.getIndexById(m[1]);
430 findHeaderCell : function(el){
431 var cell = this.findCell(el);
432 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
436 findHeaderIndex : function(el){
437 return this.findCellIndex(el, this.hdCls);
440 <div id="method-Ext.grid.GridView-findRow"></div>/**
441 * Return the HtmlElement representing the grid row which contains the passed element.
442 * @param {HTMLElement} el The target HTMLElement
443 * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
445 findRow : function(el){
449 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
452 <div id="method-Ext.grid.GridView-findRowIndex"></div>/**
453 * <p>Return the index of the grid row which contains the passed HTMLElement.</p>
454 * See also {@link #findCellIndex}
455 * @param {HTMLElement} el The target HTMLElement
456 * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
458 findRowIndex : function(el){
459 var r = this.findRow(el);
460 return r ? r.rowIndex : false;
463 <div id="method-Ext.grid.GridView-findRowBody"></div>/**
464 * Return the HtmlElement representing the grid row body which contains the passed element.
465 * @param {HTMLElement} el The target HTMLElement
466 * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
468 findRowBody : function(el){
472 return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
475 // getter methods for fetching elements dynamically in the grid
477 <div id="method-Ext.grid.GridView-getRow"></div>/**
478 * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
479 * @param {Number} index The row index
480 * @return {HtmlElement} The div element.
482 getRow : function(row){
483 return this.getRows()[row];
486 <div id="method-Ext.grid.GridView-getCell"></div>/**
487 * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
488 * @param {Number} row The row index in which to find the cell.
489 * @param {Number} col The column index of the cell.
490 * @return {HtmlElement} The td at the specified coordinates.
492 getCell : function(row, col){
493 return this.getRow(row).getElementsByTagName('td')[col];
496 <div id="method-Ext.grid.GridView-getHeaderCell"></div>/**
497 * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
498 * @param {Number} index The column index
499 * @return {HtmlElement} The td element.
501 getHeaderCell : function(index){
502 return this.mainHd.dom.getElementsByTagName('td')[index];
505 // manipulating elements
507 // private - use getRowClass to apply custom row classes
508 addRowClass : function(row, cls){
509 var r = this.getRow(row);
511 this.fly(r).addClass(cls);
516 removeRowClass : function(row, cls){
517 var r = this.getRow(row);
519 this.fly(r).removeClass(cls);
524 removeRow : function(row){
525 Ext.removeNode(this.getRow(row));
526 this.syncFocusEl(row);
530 removeRows : function(firstRow, lastRow){
531 var bd = this.mainBody.dom;
532 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
533 Ext.removeNode(bd.childNodes[firstRow]);
535 this.syncFocusEl(firstRow);
541 getScrollState : function(){
542 var sb = this.scroller.dom;
543 return {left: sb.scrollLeft, top: sb.scrollTop};
547 restoreScroll : function(state){
548 var sb = this.scroller.dom;
549 sb.scrollLeft = state.left;
550 sb.scrollTop = state.top;
553 <div id="method-Ext.grid.GridView-scrollToTop"></div>/**
554 * Scrolls the grid to the top
556 scrollToTop : function(){
557 this.scroller.dom.scrollTop = 0;
558 this.scroller.dom.scrollLeft = 0;
562 syncScroll : function(){
563 this.syncHeaderScroll();
564 var mb = this.scroller.dom;
565 this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
569 syncHeaderScroll : function(){
570 var mb = this.scroller.dom;
571 this.innerHd.scrollLeft = mb.scrollLeft;
572 this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
576 updateSortIcon : function(col, dir){
577 var sc = this.sortClasses;
578 var hds = this.mainHd.select('td').removeClass(sc);
579 hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]);
583 updateAllColumnWidths : function(){
584 var tw = this.getTotalWidth(),
585 clen = this.cm.getColumnCount(),
590 for(i = 0; i < clen; i++){
591 ws[i] = this.getColumnWidth(i);
594 this.innerHd.firstChild.style.width = this.getOffsetWidth();
595 this.innerHd.firstChild.firstChild.style.width = tw;
596 this.mainBody.dom.style.width = tw;
598 for(i = 0; i < clen; i++){
599 var hd = this.getHeaderCell(i);
600 hd.style.width = ws[i];
603 var ns = this.getRows(), row, trow;
604 for(i = 0, len = ns.length; i < len; i++){
606 row.style.width = tw;
608 row.firstChild.style.width = tw;
609 trow = row.firstChild.rows[0];
610 for (var j = 0; j < clen; j++) {
611 trow.childNodes[j].style.width = ws[j];
616 this.onAllColumnWidthsUpdated(ws, tw);
620 updateColumnWidth : function(col, width){
621 var w = this.getColumnWidth(col);
622 var tw = this.getTotalWidth();
623 this.innerHd.firstChild.style.width = this.getOffsetWidth();
624 this.innerHd.firstChild.firstChild.style.width = tw;
625 this.mainBody.dom.style.width = tw;
626 var hd = this.getHeaderCell(col);
629 var ns = this.getRows(), row;
630 for(var i = 0, len = ns.length; i < len; i++){
632 row.style.width = tw;
634 row.firstChild.style.width = tw;
635 row.firstChild.rows[0].childNodes[col].style.width = w;
639 this.onColumnWidthUpdated(col, w, tw);
643 updateColumnHidden : function(col, hidden){
644 var tw = this.getTotalWidth();
645 this.innerHd.firstChild.style.width = this.getOffsetWidth();
646 this.innerHd.firstChild.firstChild.style.width = tw;
647 this.mainBody.dom.style.width = tw;
648 var display = hidden ? 'none' : '';
650 var hd = this.getHeaderCell(col);
651 hd.style.display = display;
653 var ns = this.getRows(), row;
654 for(var i = 0, len = ns.length; i < len; i++){
656 row.style.width = tw;
658 row.firstChild.style.width = tw;
659 row.firstChild.rows[0].childNodes[col].style.display = display;
663 this.onColumnHiddenUpdated(col, hidden, tw);
664 delete this.lastViewWidth; // force recalc
670 * Renders all of the rows to a string buffer and returns the string. This is called internally
671 * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM.
672 * @param {Array} columns The column data acquired from getColumnData.
673 * @param {Array} records The array of records to render
674 * @param {Ext.data.Store} store The store to render the rows from
675 * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of
676 * the rows so this is used to maintain logic for striping etc
677 * @param {Number} colCount The total number of columns in the column model
678 * @param {Boolean} stripe True to stripe the rows
679 * @return {String} A string containing the HTML for the rendered rows
681 doRender : function(columns, records, store, startRow, colCount, stripe) {
682 var templates = this.templates,
683 cellTemplate = templates.cell,
684 rowTemplate = templates.row,
687 var tstyle = 'width:' + this.getTotalWidth() + ';';
692 rowParams = {tstyle: tstyle},
697 //build up each row's HTML
698 for (var j = 0, len = records.length; j < len; j++) {
702 var rowIndex = j + startRow;
704 //build up each column's HTML
705 for (var i = 0; i < colCount; i++) {
709 meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
710 meta.attr = meta.cellAttr = '';
711 meta.style = column.style;
712 meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
714 if (Ext.isEmpty(meta.value)) {
715 meta.value = ' ';
718 if (this.markDirty && record.dirty && Ext.isDefined(record.modified[column.name])) {
719 meta.css += ' x-grid3-dirty-cell';
722 colBuffer[colBuffer.length] = cellTemplate.apply(meta);
725 //set up row striping and row dirtiness CSS classes
728 if (stripe && ((rowIndex + 1) % 2 === 0)) {
729 alt[0] = 'x-grid3-row-alt';
733 alt[1] = ' x-grid3-dirty-row';
736 rowParams.cols = colCount;
738 if (this.getRowClass) {
739 alt[2] = this.getRowClass(record, rowIndex, rowParams, store);
742 rowParams.alt = alt.join(' ');
743 rowParams.cells = colBuffer.join('');
745 rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams);
748 return rowBuffer.join('');
752 processRows : function(startRow, skipStripe) {
753 if (!this.ds || this.ds.getCount() < 1) {
757 var rows = this.getRows(),
761 skipStripe = skipStripe || !this.grid.stripeRows;
762 startRow = startRow || 0;
764 for (i = 0; i<len; i++) {
769 r.className = r.className.replace(this.rowClsRe, ' ');
770 if ((i + 1) % 2 === 0){
771 r.className += ' x-grid3-row-alt';
777 // add first/last-row classes
778 if (startRow === 0) {
779 Ext.fly(rows[0]).addClass(this.firstRowCls);
782 Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
785 afterRender : function(){
786 if(!this.ds || !this.cm){
789 this.mainBody.dom.innerHTML = this.renderRows() || ' ';
790 this.processRows(0, true);
792 if(this.deferEmptyText !== true){
793 this.applyEmptyText();
795 this.grid.fireEvent('viewready', this.grid);
800 * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not
801 * render rows from the store, just the surrounding UI elements. It also sets up listeners on the UI elements
802 * and sets up options like column menus, moving and resizing.
804 renderUI : function() {
805 var templates = this.templates,
806 header = this.renderHeaders(),
807 body = templates.body.apply({rows:' '});
809 var html = templates.master.apply({
812 ostyle: 'width:' + this.getOffsetWidth() + ';',
813 bstyle: 'width:' + this.getTotalWidth() + ';'
818 g.getGridEl().dom.innerHTML = html;
822 // get mousedowns early
823 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
827 mouseover: this.handleHdOver,
828 mouseout : this.handleHdOut,
829 mousemove: this.handleHdMove
832 this.scroller.on('scroll', this.syncScroll, this);
833 if (g.enableColumnResize !== false) {
834 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
837 if (g.enableColumnMove) {
838 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
839 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
842 if (g.enableHdMenu !== false) {
843 this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
845 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
846 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
849 if (g.enableColumnHide !== false) {
850 this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
853 beforeshow: this.beforeColMenuShow,
854 itemclick : this.handleHdMenuClick
856 this.hmenu.add('-', {
859 text: this.columnsText,
861 iconCls: 'x-cols-icon'
865 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
868 if (g.trackMouseOver) {
871 mouseover: this.onRowOver,
872 mouseout : this.onRowOut
876 if (g.enableDragDrop || g.enableDrag) {
877 this.dragZone = new Ext.grid.GridDragZone(g, {
878 ddGroup : g.ddGroup || 'GridDD'
882 this.updateHeaderSortState();
886 processEvent : function(name, e) {
887 var t = e.getTarget(),
889 header = this.findHeaderIndex(t);
890 g.fireEvent(name, e);
891 if (header !== false) {
892 g.fireEvent('header' + name, g, header, e);
894 var row = this.findRowIndex(t),
898 g.fireEvent('row' + name, g, row, e);
899 cell = this.findCellIndex(t);
900 if (cell !== false) {
901 g.fireEvent('cell' + name, g, row, cell, e);
903 body = this.findRowBody(t);
905 g.fireEvent('rowbody' + name, g, row, e);
909 g.fireEvent('container' + name, g, e);
915 layout : function() {
917 return; // not rendered
920 var c = g.getGridEl();
921 var csize = c.getSize(true);
922 var vw = csize.width;
924 if(!g.hideHeaders && (vw < 20 || csize.height < 20)){ // display: none?
929 this.scroller.dom.style.overflow = 'visible';
931 this.scroller.dom.style.position = 'static';
934 this.el.setSize(csize.width, csize.height);
936 var hdHeight = this.mainHd.getHeight();
937 var vh = csize.height - (hdHeight);
939 this.scroller.setSize(vw, vh);
941 this.innerHd.style.width = (vw)+'px';
945 if(this.lastViewWidth != vw){
946 this.fitColumns(false, false);
947 this.lastViewWidth = vw;
951 this.syncHeaderScroll();
953 this.onLayout(vw, vh);
956 // template functions for subclasses and plugins
957 // these functions include precalculated values
958 onLayout : function(vw, vh){
962 onColumnWidthUpdated : function(col, w, tw){
966 onAllColumnWidthsUpdated : function(ws, tw){
970 onColumnHiddenUpdated : function(col, hidden, tw){
974 updateColumnText : function(col, text){
978 afterMove : function(colIndex){
982 /* ----------------------------------- Core Specific -------------------------------------------*/
984 init : function(grid){
987 this.initTemplates();
988 this.initData(grid.store, grid.colModel);
993 getColumnId : function(index){
994 return this.cm.getColumnId(index);
998 getOffsetWidth : function() {
999 return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
1002 getScrollOffset: function(){
1003 return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
1008 * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just
1010 * @return {String} Rendered header row
1012 renderHeaders : function() {
1014 ts = this.templates,
1018 len = cm.getColumnCount(),
1021 for (var i = 0; i < len; i++) {
1022 p.id = cm.getColumnId(i);
1023 p.value = cm.getColumnHeader(i) || '';
1024 p.style = this.getColumnStyle(i, true);
1025 p.tooltip = this.getColumnTooltip(i);
1026 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
1028 if (cm.config[i].align == 'right') {
1029 p.istyle = 'padding-right:16px';
1033 cb[cb.length] = ct.apply(p);
1035 return ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'});
1039 getColumnTooltip : function(i){
1040 var tt = this.cm.getColumnTooltip(i);
1042 if(Ext.QuickTips.isEnabled()){
1043 return 'ext:qtip="'+tt+'"';
1045 return 'title="'+tt+'"';
1052 beforeUpdate : function(){
1053 this.grid.stopEditing(true);
1057 updateHeaders : function(){
1058 this.innerHd.firstChild.innerHTML = this.renderHeaders();
1059 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1060 this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
1063 <div id="method-Ext.grid.GridView-focusRow"></div>/**
1064 * Focuses the specified row.
1065 * @param {Number} row The row index
1067 focusRow : function(row){
1068 this.focusCell(row, 0, false);
1071 <div id="method-Ext.grid.GridView-focusCell"></div>/**
1072 * Focuses the specified cell.
1073 * @param {Number} row The row index
1074 * @param {Number} col The column index
1076 focusCell : function(row, col, hscroll){
1077 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
1079 this.focusEl.focus();
1081 this.focusEl.focus.defer(1, this.focusEl);
1085 resolveCell : function(row, col, hscroll){
1086 if(!Ext.isNumber(row)){
1092 if(row < 0 || row >= this.ds.getCount()){
1095 col = (col !== undefined ? col : 0);
1097 var rowEl = this.getRow(row),
1099 colCount = cm.getColumnCount(),
1101 if(!(hscroll === false && col === 0)){
1102 while(col < colCount && cm.isHidden(col)){
1105 cellEl = this.getCell(row, col);
1108 return {row: rowEl, cell: cellEl};
1111 getResolvedXY : function(resolved){
1115 var s = this.scroller.dom, c = resolved.cell, r = resolved.row;
1116 return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()];
1119 syncFocusEl : function(row, col, hscroll){
1121 if(!Ext.isArray(xy)){
1122 row = Math.min(row, Math.max(0, this.getRows().length-1));
1126 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
1128 this.focusEl.setXY(xy||this.scroller.getXY());
1131 ensureVisible : function(row, col, hscroll){
1132 var resolved = this.resolveCell(row, col, hscroll);
1133 if(!resolved || !resolved.row){
1137 var rowEl = resolved.row,
1138 cellEl = resolved.cell,
1139 c = this.scroller.dom,
1144 while(p && p != stop){
1145 ctop += p.offsetTop;
1149 ctop -= this.mainHd.dom.offsetHeight;
1150 stop = parseInt(c.scrollTop, 10);
1152 var cbot = ctop + rowEl.offsetHeight,
1153 ch = c.clientHeight,
1159 }else if(cbot > sbot){
1160 c.scrollTop = cbot-ch;
1163 if(hscroll !== false){
1164 var cleft = parseInt(cellEl.offsetLeft, 10);
1165 var cright = cleft + cellEl.offsetWidth;
1167 var sleft = parseInt(c.scrollLeft, 10);
1168 var sright = sleft + c.clientWidth;
1170 c.scrollLeft = cleft;
1171 }else if(cright > sright){
1172 c.scrollLeft = cright-c.clientWidth;
1175 return this.getResolvedXY(resolved);
1179 insertRows : function(dm, firstRow, lastRow, isUpdate) {
1180 var last = dm.getCount() - 1;
1181 if( !isUpdate && firstRow === 0 && lastRow >= last) {
1182 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1184 this.fireEvent('rowsinserted', this, firstRow, lastRow);
1187 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1189 var html = this.renderRows(firstRow, lastRow),
1190 before = this.getRow(firstRow);
1193 Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
1195 Ext.DomHelper.insertHtml('beforeBegin', before, html);
1197 var r = this.getRow(last - 1);
1199 Ext.fly(r).removeClass(this.lastRowCls);
1201 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
1204 this.fireEvent('rowsinserted', this, firstRow, lastRow);
1205 this.processRows(firstRow);
1206 } else if (firstRow === 0 || firstRow >= last) {
1207 //ensure first/last row is kept after an update.
1208 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
1211 this.syncFocusEl(firstRow);
1215 deleteRows : function(dm, firstRow, lastRow){
1216 if(dm.getRowCount()<1){
1219 this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
1221 this.removeRows(firstRow, lastRow);
1223 this.processRows(firstRow);
1224 this.fireEvent('rowsdeleted', this, firstRow, lastRow);
1229 getColumnStyle : function(col, isHeader){
1230 var style = !isHeader ? (this.cm.config[col].css || '') : '';
1231 style += 'width:'+this.getColumnWidth(col)+';';
1232 if(this.cm.isHidden(col)){
1233 style += 'display:none;';
1235 var align = this.cm.config[col].align;
1237 style += 'text-align:'+align+';';
1243 getColumnWidth : function(col){
1244 var w = this.cm.getColumnWidth(col);
1245 if(Ext.isNumber(w)){
1246 return (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? w : (w - this.borderWidth > 0 ? w - this.borderWidth : 0)) + 'px';
1252 getTotalWidth : function(){
1253 return this.cm.getTotalWidth()+'px';
1257 fitColumns : function(preventRefresh, onlyExpand, omitColumn){
1258 var cm = this.cm, i;
1259 var tw = cm.getTotalWidth(false);
1260 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
1262 if(aw < 20){ // not initialized, so don't screw up the default widths
1265 var extra = aw - tw;
1271 var vc = cm.getColumnCount(true);
1272 var ac = vc-(Ext.isNumber(omitColumn) ? 1 : 0);
1275 omitColumn = undefined;
1277 var colCount = cm.getColumnCount();
1282 for (i = 0; i < colCount; i++){
1283 if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
1284 w = cm.getColumnWidth(i);
1291 var frac = (aw - cm.getTotalWidth())/width;
1292 while (cols.length){
1295 cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
1298 if((tw = cm.getTotalWidth(false)) > aw){
1299 var adjustCol = ac != vc ? omitColumn : extraCol;
1300 cm.setColumnWidth(adjustCol, Math.max(1,
1301 cm.getColumnWidth(adjustCol)- (tw-aw)), true);
1304 if(preventRefresh !== true){
1305 this.updateAllColumnWidths();
1313 autoExpand : function(preventUpdate){
1314 var g = this.grid, cm = this.cm;
1315 if(!this.userResized && g.autoExpandColumn){
1316 var tw = cm.getTotalWidth(false);
1317 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
1319 var ci = cm.getIndexById(g.autoExpandColumn);
1320 var currentWidth = cm.getColumnWidth(ci);
1321 var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
1322 if(cw != currentWidth){
1323 cm.setColumnWidth(ci, cw, true);
1324 if(preventUpdate !== true){
1325 this.updateColumnWidth(ci, cw);
1334 * Returns an array of column configurations - one for each column
1335 * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
1337 getColumnData : function(){
1338 // build a map for all the columns
1341 colCount = cm.getColumnCount();
1343 for (var i = 0; i < colCount; i++) {
1344 var name = cm.getDataIndex(i);
1347 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
1348 renderer: cm.getRenderer(i),
1349 scope : cm.getRendererScope(i),
1350 id : cm.getColumnId(i),
1351 style : this.getColumnStyle(i)
1359 renderRows : function(startRow, endRow){
1360 // pull in all the crap needed to render rows
1361 var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
1362 var colCount = cm.getColumnCount();
1364 if(ds.getCount() < 1){
1368 var cs = this.getColumnData();
1370 startRow = startRow || 0;
1371 endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow;
1373 // records to render
1374 var rs = ds.getRange(startRow, endRow);
1376 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
1380 renderBody : function(){
1381 var markup = this.renderRows() || ' ';
1382 return this.templates.body.apply({rows: markup});
1386 refreshRow : function(record){
1387 var ds = this.ds, index;
1388 if(Ext.isNumber(record)){
1390 record = ds.getAt(index);
1395 index = ds.indexOf(record);
1400 this.insertRows(ds, index, index, true);
1401 this.getRow(index).rowIndex = index;
1402 this.onRemove(ds, record, index+1, true);
1403 this.fireEvent('rowupdated', this, index, record);
1406 <div id="method-Ext.grid.GridView-refresh"></div>/**
1407 * Refreshs the grid UI
1408 * @param {Boolean} headersToo (optional) True to also refresh the headers
1410 refresh : function(headersToo){
1411 this.fireEvent('beforerefresh', this);
1412 this.grid.stopEditing(true);
1414 var result = this.renderBody();
1415 this.mainBody.update(result).setWidth(this.getTotalWidth());
1416 if(headersToo === true){
1417 this.updateHeaders();
1418 this.updateHeaderSortState();
1420 this.processRows(0, true);
1422 this.applyEmptyText();
1423 this.fireEvent('refresh', this);
1428 * Displays the configured emptyText if there are currently no rows to display
1430 applyEmptyText : function(){
1431 if(this.emptyText && !this.hasRows()){
1432 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1438 * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
1439 * if the sorting has changed since this function was last run.
1441 updateHeaderSortState : function(){
1442 var state = this.ds.getSortState();
1447 if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
1448 this.grid.fireEvent('sortchange', this.grid, state);
1451 this.sortState = state;
1453 var sortColumn = this.cm.findColumnIndex(state.field);
1454 if (sortColumn != -1){
1455 var sortDir = state.direction;
1456 this.updateSortIcon(sortColumn, sortDir);
1462 * Removes any sorting indicator classes from the column headers
1464 clearHeaderSortState : function(){
1465 if (!this.sortState) {
1468 this.grid.fireEvent('sortchange', this.grid, null);
1469 this.mainHd.select('td').removeClass(this.sortClasses);
1470 delete this.sortState;
1474 destroy : function(){
1475 if (this.scrollToTopTask && this.scrollToTopTask.cancel){
1476 this.scrollToTopTask.cancel();
1479 Ext.menu.MenuMgr.unregister(this.colMenu);
1480 this.colMenu.destroy();
1481 delete this.colMenu;
1484 Ext.menu.MenuMgr.unregister(this.hmenu);
1485 this.hmenu.destroy();
1489 this.initData(null, null);
1490 this.purgeListeners();
1491 Ext.fly(this.innerHd).un("click", this.handleHdDown, this);
1493 if(this.grid.enableColumnMove){
1496 this.columnDrag.proxy.ghost,
1497 this.columnDrag.proxy.el,
1499 this.columnDrop.proxyTop,
1500 this.columnDrop.proxyBottom,
1501 this.columnDrag.dragData.ddel,
1502 this.columnDrag.dragData.header
1504 if (this.columnDrag.proxy.anim) {
1505 Ext.destroy(this.columnDrag.proxy.anim);
1507 delete this.columnDrag.proxy.ghost;
1508 delete this.columnDrag.dragData.ddel;
1509 delete this.columnDrag.dragData.header;
1510 this.columnDrag.destroy();
1511 delete Ext.dd.DDM.locationCache[this.columnDrag.id];
1512 delete this.columnDrag._domRef;
1514 delete this.columnDrop.proxyTop;
1515 delete this.columnDrop.proxyBottom;
1516 this.columnDrop.destroy();
1517 delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id];
1518 delete this.columnDrop._domRef;
1519 delete Ext.dd.DDM.ids[this.columnDrop.ddGroup];
1522 if (this.splitZone){ // enableColumnResize
1523 this.splitZone.destroy();
1524 delete this.splitZone._domRef;
1525 delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id];
1528 Ext.fly(this.innerHd).removeAllListeners();
1529 Ext.removeNode(this.innerHd);
1530 delete this.innerHd;
1547 delete this.grid.container;
1550 this.dragZone.destroy();
1553 Ext.dd.DDM.currentTarget = null;
1554 delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id];
1556 Ext.EventManager.removeResizeListener(this.onWindowResize, this);
1560 onDenyColumnHide : function(){
1565 render : function(){
1567 var ct = this.grid.ownerCt;
1568 if (ct && ct.getLayout()){
1569 ct.on('afterlayout', function(){
1570 this.fitColumns(true, true);
1571 this.updateHeaders();
1572 }, this, {single: true});
1574 this.fitColumns(true, true);
1576 }else if(this.forceFit){
1577 this.fitColumns(true, false);
1578 }else if(this.grid.autoExpandColumn){
1579 this.autoExpand(true);
1585 /* --------------------------------- Model Events and Handlers --------------------------------*/
1587 initData : function(ds, cm){
1589 this.ds.un('load', this.onLoad, this);
1590 this.ds.un('datachanged', this.onDataChange, this);
1591 this.ds.un('add', this.onAdd, this);
1592 this.ds.un('remove', this.onRemove, this);
1593 this.ds.un('update', this.onUpdate, this);
1594 this.ds.un('clear', this.onClear, this);
1595 if(this.ds !== ds && this.ds.autoDestroy){
1603 datachanged: this.onDataChange,
1605 remove: this.onRemove,
1606 update: this.onUpdate,
1613 this.cm.un('configchange', this.onColConfigChange, this);
1614 this.cm.un('widthchange', this.onColWidthChange, this);
1615 this.cm.un('headerchange', this.onHeaderChange, this);
1616 this.cm.un('hiddenchange', this.onHiddenChange, this);
1617 this.cm.un('columnmoved', this.onColumnMove, this);
1620 delete this.lastViewWidth;
1623 configchange: this.onColConfigChange,
1624 widthchange: this.onColWidthChange,
1625 headerchange: this.onHeaderChange,
1626 hiddenchange: this.onHiddenChange,
1627 columnmoved: this.onColumnMove
1634 onDataChange : function(){
1636 this.updateHeaderSortState();
1637 this.syncFocusEl(0);
1641 onClear : function(){
1643 this.syncFocusEl(0);
1647 onUpdate : function(ds, record){
1648 this.refreshRow(record);
1652 onAdd : function(ds, records, index){
1653 this.insertRows(ds, index, index + (records.length-1));
1657 onRemove : function(ds, record, index, isUpdate){
1658 if(isUpdate !== true){
1659 this.fireEvent('beforerowremoved', this, index, record);
1661 this.removeRow(index);
1662 if(isUpdate !== true){
1663 this.processRows(index);
1664 this.applyEmptyText();
1665 this.fireEvent('rowremoved', this, index, record);
1670 onLoad : function(){
1672 if (!this.scrollToTopTask) {
1673 this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
1675 this.scrollToTopTask.delay(1);
1682 onColWidthChange : function(cm, col, width){
1683 this.updateColumnWidth(col, width);
1687 onHeaderChange : function(cm, col, text){
1688 this.updateHeaders();
1692 onHiddenChange : function(cm, col, hidden){
1693 this.updateColumnHidden(col, hidden);
1697 onColumnMove : function(cm, oldIndex, newIndex){
1698 this.indexMap = null;
1699 var s = this.getScrollState();
1701 this.restoreScroll(s);
1702 this.afterMove(newIndex);
1703 this.grid.fireEvent('columnmove', oldIndex, newIndex);
1707 onColConfigChange : function(){
1708 delete this.lastViewWidth;
1709 this.indexMap = null;
1713 /* -------------------- UI Events and Handlers ------------------------------ */
1715 initUI : function(grid){
1716 grid.on('headerclick', this.onHeaderClick, this);
1720 initEvents : function(){
1724 onHeaderClick : function(g, index){
1725 if(this.headersDisabled || !this.cm.isSortable(index)){
1728 g.stopEditing(true);
1729 g.store.sort(this.cm.getDataIndex(index));
1733 onRowOver : function(e, t){
1735 if((row = this.findRowIndex(t)) !== false){
1736 this.addRowClass(row, 'x-grid3-row-over');
1741 onRowOut : function(e, t){
1743 if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
1744 this.removeRowClass(row, 'x-grid3-row-over');
1749 handleWheel : function(e){
1750 e.stopPropagation();
1754 onRowSelect : function(row){
1755 this.addRowClass(row, this.selectedRowClass);
1759 onRowDeselect : function(row){
1760 this.removeRowClass(row, this.selectedRowClass);
1764 onCellSelect : function(row, col){
1765 var cell = this.getCell(row, col);
1767 this.fly(cell).addClass('x-grid3-cell-selected');
1772 onCellDeselect : function(row, col){
1773 var cell = this.getCell(row, col);
1775 this.fly(cell).removeClass('x-grid3-cell-selected');
1780 onColumnSplitterMoved : function(i, w){
1781 this.userResized = true;
1782 var cm = this.grid.colModel;
1783 cm.setColumnWidth(i, w, true);
1786 this.fitColumns(true, false, i);
1787 this.updateAllColumnWidths();
1789 this.updateColumnWidth(i, w);
1790 this.syncHeaderScroll();
1793 this.grid.fireEvent('columnresize', i, w);
1797 handleHdMenuClick : function(item){
1798 var index = this.hdCtxIndex,
1801 id = item.getItemId();
1804 ds.sort(cm.getDataIndex(index), 'ASC');
1807 ds.sort(cm.getDataIndex(index), 'DESC');
1810 index = cm.getIndexById(id.substr(4));
1812 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
1813 this.onDenyColumnHide();
1816 cm.setHidden(index, item.checked);
1823 isHideableColumn : function(c){
1828 beforeColMenuShow : function(){
1829 var cm = this.cm, colCount = cm.getColumnCount();
1830 this.colMenu.removeAll();
1831 for(var i = 0; i < colCount; i++){
1832 if(cm.config[i].hideable !== false){
1833 this.colMenu.add(new Ext.menu.CheckItem({
1834 itemId: 'col-'+cm.getColumnId(i),
1835 text: cm.getColumnHeader(i),
1836 checked: !cm.isHidden(i),
1838 disabled: cm.config[i].hideable === false
1845 handleHdDown : function(e, t){
1846 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
1848 var hd = this.findHeaderCell(t);
1849 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
1850 var index = this.getCellIndex(hd);
1851 this.hdCtxIndex = index;
1852 var ms = this.hmenu.items, cm = this.cm;
1853 ms.get('asc').setDisabled(!cm.isSortable(index));
1854 ms.get('desc').setDisabled(!cm.isSortable(index));
1855 this.hmenu.on('hide', function(){
1856 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
1857 }, this, {single:true});
1858 this.hmenu.show(t, 'tl-bl?');
1863 handleHdOver : function(e, t){
1864 var hd = this.findHeaderCell(t);
1865 if(hd && !this.headersDisabled){
1866 this.activeHdRef = t;
1867 this.activeHdIndex = this.getCellIndex(hd);
1868 var fly = this.fly(hd);
1869 this.activeHdRegion = fly.getRegion();
1870 if(!this.cm.isMenuDisabled(this.activeHdIndex)){
1871 fly.addClass('x-grid3-hd-over');
1872 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
1873 if(this.activeHdBtn){
1874 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
1881 handleHdMove : function(e, t){
1882 var hd = this.findHeaderCell(this.activeHdRef);
1883 if(hd && !this.headersDisabled){
1884 var hw = this.splitHandleWidth || 5,
1885 r = this.activeHdRegion,
1889 if(this.grid.enableColumnResize !== false){
1890 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
1891 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
1892 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
1893 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
1901 handleHdOut : function(e, t){
1902 var hd = this.findHeaderCell(t);
1903 if(hd && (!Ext.isIE || !e.within(hd, true))){
1904 this.activeHdRef = null;
1905 this.fly(hd).removeClass('x-grid3-hd-over');
1906 hd.style.cursor = '';
1911 hasRows : function(){
1912 var fc = this.mainBody.dom.firstChild;
1913 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
1917 bind : function(d, c){
1918 this.initData(d, c);
1924 // This is a support class used internally by the Grid components
1925 Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
1927 constructor: function(grid, hd){
1929 this.view = grid.getView();
1930 this.marker = this.view.resizeMarker;
1931 this.proxy = this.view.resizeProxy;
1932 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
1933 'gridSplitters' + this.grid.getGridEl().id, {
1934 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
1936 this.scroll = false;
1937 this.hw = this.view.splitHandleWidth || 5;
1940 b4StartDrag : function(x, y){
1941 this.dragHeadersDisabled = this.view.headersDisabled;
1942 this.view.headersDisabled = true;
1943 var h = this.view.mainWrap.getHeight();
1944 this.marker.setHeight(h);
1946 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
1947 this.proxy.setHeight(h);
1948 var w = this.cm.getColumnWidth(this.cellIndex),
1949 minw = Math.max(w-this.grid.minColumnWidth, 0);
1950 this.resetConstraints();
1951 this.setXConstraint(minw, 1000);
1952 this.setYConstraint(0, 0);
1953 this.minX = x - minw;
1954 this.maxX = x + 1000;
1956 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
1959 allowHeaderDrag : function(e){
1963 handleMouseDown : function(e){
1964 var t = this.view.findHeaderCell(e.getTarget());
1965 if(t && this.allowHeaderDrag(e)){
1966 var xy = this.view.fly(t).getXY(),
1969 exy = e.getXY(), ex = exy[0],
1970 w = t.offsetWidth, adjust = false;
1972 if((ex - x) <= this.hw){
1974 }else if((x+w) - ex <= this.hw){
1977 if(adjust !== false){
1978 this.cm = this.grid.colModel;
1979 var ci = this.view.getCellIndex(t);
1981 if (ci + adjust < 0) {
1984 while(this.cm.isHidden(ci+adjust)){
1991 this.cellIndex = ci+adjust;
1993 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
1994 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
1996 }else if(this.view.columnDrag){
1997 this.view.columnDrag.callHandleMouseDown(e);
2002 endDrag : function(e){
2005 endX = Math.max(this.minX, e.getPageX()),
2006 diff = endX - this.startPos,
2007 disabled = this.dragHeadersDisabled;
2009 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
2010 setTimeout(function(){
2011 v.headersDisabled = disabled;
2015 autoOffset : function(){