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.2
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.isFixed(i) && i !== omitColumn){
1284 w = cm.getColumnWidth(i);
1286 if(!cm.isHidden(i)){
1292 var frac = (aw - cm.getTotalWidth())/width;
1293 while (cols.length){
1296 cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
1299 if((tw = cm.getTotalWidth(false)) > aw){
1300 var adjustCol = ac != vc ? omitColumn : extraCol;
1301 cm.setColumnWidth(adjustCol, Math.max(1,
1302 cm.getColumnWidth(adjustCol)- (tw-aw)), true);
1305 if(preventRefresh !== true){
1306 this.updateAllColumnWidths();
1314 autoExpand : function(preventUpdate){
1315 var g = this.grid, cm = this.cm;
1316 if(!this.userResized && g.autoExpandColumn){
1317 var tw = cm.getTotalWidth(false);
1318 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
1320 var ci = cm.getIndexById(g.autoExpandColumn);
1321 var currentWidth = cm.getColumnWidth(ci);
1322 var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
1323 if(cw != currentWidth){
1324 cm.setColumnWidth(ci, cw, true);
1325 if(preventUpdate !== true){
1326 this.updateColumnWidth(ci, cw);
1335 * Returns an array of column configurations - one for each column
1336 * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
1338 getColumnData : function(){
1339 // build a map for all the columns
1342 colCount = cm.getColumnCount();
1344 for (var i = 0; i < colCount; i++) {
1345 var name = cm.getDataIndex(i);
1348 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
1349 renderer: cm.getRenderer(i),
1350 scope : cm.getRendererScope(i),
1351 id : cm.getColumnId(i),
1352 style : this.getColumnStyle(i)
1360 renderRows : function(startRow, endRow){
1361 // pull in all the crap needed to render rows
1362 var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
1363 var colCount = cm.getColumnCount();
1365 if(ds.getCount() < 1){
1369 var cs = this.getColumnData();
1371 startRow = startRow || 0;
1372 endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow;
1374 // records to render
1375 var rs = ds.getRange(startRow, endRow);
1377 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
1381 renderBody : function(){
1382 var markup = this.renderRows() || ' ';
1383 return this.templates.body.apply({rows: markup});
1387 refreshRow : function(record){
1388 var ds = this.ds, index;
1389 if(Ext.isNumber(record)){
1391 record = ds.getAt(index);
1396 index = ds.indexOf(record);
1401 this.insertRows(ds, index, index, true);
1402 this.getRow(index).rowIndex = index;
1403 this.onRemove(ds, record, index+1, true);
1404 this.fireEvent('rowupdated', this, index, record);
1407 <div id="method-Ext.grid.GridView-refresh"></div>/**
1408 * Refreshs the grid UI
1409 * @param {Boolean} headersToo (optional) True to also refresh the headers
1411 refresh : function(headersToo){
1412 this.fireEvent('beforerefresh', this);
1413 this.grid.stopEditing(true);
1415 var result = this.renderBody();
1416 this.mainBody.update(result).setWidth(this.getTotalWidth());
1417 if(headersToo === true){
1418 this.updateHeaders();
1419 this.updateHeaderSortState();
1421 this.processRows(0, true);
1423 this.applyEmptyText();
1424 this.fireEvent('refresh', this);
1429 * Displays the configured emptyText if there are currently no rows to display
1431 applyEmptyText : function(){
1432 if(this.emptyText && !this.hasRows()){
1433 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1439 * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
1440 * if the sorting has changed since this function was last run.
1442 updateHeaderSortState : function(){
1443 var state = this.ds.getSortState();
1448 if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
1449 this.grid.fireEvent('sortchange', this.grid, state);
1452 this.sortState = state;
1454 var sortColumn = this.cm.findColumnIndex(state.field);
1455 if (sortColumn != -1){
1456 var sortDir = state.direction;
1457 this.updateSortIcon(sortColumn, sortDir);
1463 * Removes any sorting indicator classes from the column headers
1465 clearHeaderSortState : function(){
1466 if (!this.sortState) {
1469 this.grid.fireEvent('sortchange', this.grid, null);
1470 this.mainHd.select('td').removeClass(this.sortClasses);
1471 delete this.sortState;
1475 destroy : function(){
1476 if (this.scrollToTopTask && this.scrollToTopTask.cancel){
1477 this.scrollToTopTask.cancel();
1480 Ext.menu.MenuMgr.unregister(this.colMenu);
1481 this.colMenu.destroy();
1482 delete this.colMenu;
1485 Ext.menu.MenuMgr.unregister(this.hmenu);
1486 this.hmenu.destroy();
1490 this.initData(null, null);
1491 this.purgeListeners();
1492 Ext.fly(this.innerHd).un("click", this.handleHdDown, this);
1494 if(this.grid.enableColumnMove){
1497 this.columnDrag.proxy.ghost,
1498 this.columnDrag.proxy.el,
1500 this.columnDrop.proxyTop,
1501 this.columnDrop.proxyBottom,
1502 this.columnDrag.dragData.ddel,
1503 this.columnDrag.dragData.header
1505 if (this.columnDrag.proxy.anim) {
1506 Ext.destroy(this.columnDrag.proxy.anim);
1508 delete this.columnDrag.proxy.ghost;
1509 delete this.columnDrag.dragData.ddel;
1510 delete this.columnDrag.dragData.header;
1511 this.columnDrag.destroy();
1512 delete Ext.dd.DDM.locationCache[this.columnDrag.id];
1513 delete this.columnDrag._domRef;
1515 delete this.columnDrop.proxyTop;
1516 delete this.columnDrop.proxyBottom;
1517 this.columnDrop.destroy();
1518 delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id];
1519 delete this.columnDrop._domRef;
1520 delete Ext.dd.DDM.ids[this.columnDrop.ddGroup];
1523 if (this.splitZone){ // enableColumnResize
1524 this.splitZone.destroy();
1525 delete this.splitZone._domRef;
1526 delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id];
1529 Ext.fly(this.innerHd).removeAllListeners();
1530 Ext.removeNode(this.innerHd);
1531 delete this.innerHd;
1548 delete this.grid.container;
1551 this.dragZone.destroy();
1554 Ext.dd.DDM.currentTarget = null;
1555 delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id];
1557 Ext.EventManager.removeResizeListener(this.onWindowResize, this);
1561 onDenyColumnHide : function(){
1566 render : function(){
1568 var ct = this.grid.ownerCt;
1569 if (ct && ct.getLayout()){
1570 ct.on('afterlayout', function(){
1571 this.fitColumns(true, true);
1572 this.updateHeaders();
1573 }, this, {single: true});
1575 this.fitColumns(true, true);
1577 }else if(this.forceFit){
1578 this.fitColumns(true, false);
1579 }else if(this.grid.autoExpandColumn){
1580 this.autoExpand(true);
1586 /* --------------------------------- Model Events and Handlers --------------------------------*/
1588 initData : function(ds, cm){
1590 this.ds.un('load', this.onLoad, this);
1591 this.ds.un('datachanged', this.onDataChange, this);
1592 this.ds.un('add', this.onAdd, this);
1593 this.ds.un('remove', this.onRemove, this);
1594 this.ds.un('update', this.onUpdate, this);
1595 this.ds.un('clear', this.onClear, this);
1596 if(this.ds !== ds && this.ds.autoDestroy){
1604 datachanged: this.onDataChange,
1606 remove: this.onRemove,
1607 update: this.onUpdate,
1614 this.cm.un('configchange', this.onColConfigChange, this);
1615 this.cm.un('widthchange', this.onColWidthChange, this);
1616 this.cm.un('headerchange', this.onHeaderChange, this);
1617 this.cm.un('hiddenchange', this.onHiddenChange, this);
1618 this.cm.un('columnmoved', this.onColumnMove, this);
1621 delete this.lastViewWidth;
1624 configchange: this.onColConfigChange,
1625 widthchange: this.onColWidthChange,
1626 headerchange: this.onHeaderChange,
1627 hiddenchange: this.onHiddenChange,
1628 columnmoved: this.onColumnMove
1635 onDataChange : function(){
1637 this.updateHeaderSortState();
1638 this.syncFocusEl(0);
1642 onClear : function(){
1644 this.syncFocusEl(0);
1648 onUpdate : function(ds, record){
1649 this.refreshRow(record);
1653 onAdd : function(ds, records, index){
1654 this.insertRows(ds, index, index + (records.length-1));
1658 onRemove : function(ds, record, index, isUpdate){
1659 if(isUpdate !== true){
1660 this.fireEvent('beforerowremoved', this, index, record);
1662 this.removeRow(index);
1663 if(isUpdate !== true){
1664 this.processRows(index);
1665 this.applyEmptyText();
1666 this.fireEvent('rowremoved', this, index, record);
1671 onLoad : function(){
1673 if (!this.scrollToTopTask) {
1674 this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
1676 this.scrollToTopTask.delay(1);
1683 onColWidthChange : function(cm, col, width){
1684 this.updateColumnWidth(col, width);
1688 onHeaderChange : function(cm, col, text){
1689 this.updateHeaders();
1693 onHiddenChange : function(cm, col, hidden){
1694 this.updateColumnHidden(col, hidden);
1698 onColumnMove : function(cm, oldIndex, newIndex){
1699 this.indexMap = null;
1700 var s = this.getScrollState();
1702 this.restoreScroll(s);
1703 this.afterMove(newIndex);
1704 this.grid.fireEvent('columnmove', oldIndex, newIndex);
1708 onColConfigChange : function(){
1709 delete this.lastViewWidth;
1710 this.indexMap = null;
1714 /* -------------------- UI Events and Handlers ------------------------------ */
1716 initUI : function(grid){
1717 grid.on('headerclick', this.onHeaderClick, this);
1721 initEvents : function(){
1725 onHeaderClick : function(g, index){
1726 if(this.headersDisabled || !this.cm.isSortable(index)){
1729 g.stopEditing(true);
1730 g.store.sort(this.cm.getDataIndex(index));
1734 onRowOver : function(e, t){
1736 if((row = this.findRowIndex(t)) !== false){
1737 this.addRowClass(row, 'x-grid3-row-over');
1742 onRowOut : function(e, t){
1744 if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
1745 this.removeRowClass(row, 'x-grid3-row-over');
1750 handleWheel : function(e){
1751 e.stopPropagation();
1755 onRowSelect : function(row){
1756 this.addRowClass(row, this.selectedRowClass);
1760 onRowDeselect : function(row){
1761 this.removeRowClass(row, this.selectedRowClass);
1765 onCellSelect : function(row, col){
1766 var cell = this.getCell(row, col);
1768 this.fly(cell).addClass('x-grid3-cell-selected');
1773 onCellDeselect : function(row, col){
1774 var cell = this.getCell(row, col);
1776 this.fly(cell).removeClass('x-grid3-cell-selected');
1781 onColumnSplitterMoved : function(i, w){
1782 this.userResized = true;
1783 var cm = this.grid.colModel;
1784 cm.setColumnWidth(i, w, true);
1787 this.fitColumns(true, false, i);
1788 this.updateAllColumnWidths();
1790 this.updateColumnWidth(i, w);
1791 this.syncHeaderScroll();
1794 this.grid.fireEvent('columnresize', i, w);
1798 handleHdMenuClick : function(item){
1799 var index = this.hdCtxIndex,
1802 id = item.getItemId();
1805 ds.sort(cm.getDataIndex(index), 'ASC');
1808 ds.sort(cm.getDataIndex(index), 'DESC');
1811 index = cm.getIndexById(id.substr(4));
1813 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
1814 this.onDenyColumnHide();
1817 cm.setHidden(index, item.checked);
1824 isHideableColumn : function(c){
1829 beforeColMenuShow : function(){
1830 var cm = this.cm, colCount = cm.getColumnCount();
1831 this.colMenu.removeAll();
1832 for(var i = 0; i < colCount; i++){
1833 if(cm.config[i].hideable !== false){
1834 this.colMenu.add(new Ext.menu.CheckItem({
1835 itemId: 'col-'+cm.getColumnId(i),
1836 text: cm.getColumnHeader(i),
1837 checked: !cm.isHidden(i),
1839 disabled: cm.config[i].hideable === false
1846 handleHdDown : function(e, t){
1847 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
1849 var hd = this.findHeaderCell(t);
1850 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
1851 var index = this.getCellIndex(hd);
1852 this.hdCtxIndex = index;
1853 var ms = this.hmenu.items, cm = this.cm;
1854 ms.get('asc').setDisabled(!cm.isSortable(index));
1855 ms.get('desc').setDisabled(!cm.isSortable(index));
1856 this.hmenu.on('hide', function(){
1857 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
1858 }, this, {single:true});
1859 this.hmenu.show(t, 'tl-bl?');
1864 handleHdOver : function(e, t){
1865 var hd = this.findHeaderCell(t);
1866 if(hd && !this.headersDisabled){
1867 this.activeHdRef = t;
1868 this.activeHdIndex = this.getCellIndex(hd);
1869 var fly = this.fly(hd);
1870 this.activeHdRegion = fly.getRegion();
1871 if(!this.cm.isMenuDisabled(this.activeHdIndex)){
1872 fly.addClass('x-grid3-hd-over');
1873 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
1874 if(this.activeHdBtn){
1875 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
1882 handleHdMove : function(e, t){
1883 var hd = this.findHeaderCell(this.activeHdRef);
1884 if(hd && !this.headersDisabled){
1885 var hw = this.splitHandleWidth || 5,
1886 r = this.activeHdRegion,
1890 if(this.grid.enableColumnResize !== false){
1891 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
1892 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
1893 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
1894 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
1902 handleHdOut : function(e, t){
1903 var hd = this.findHeaderCell(t);
1904 if(hd && (!Ext.isIE || !e.within(hd, true))){
1905 this.activeHdRef = null;
1906 this.fly(hd).removeClass('x-grid3-hd-over');
1907 hd.style.cursor = '';
1912 hasRows : function(){
1913 var fc = this.mainBody.dom.firstChild;
1914 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
1918 bind : function(d, c){
1919 this.initData(d, c);
1925 // This is a support class used internally by the Grid components
1926 Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
1928 constructor: function(grid, hd){
1930 this.view = grid.getView();
1931 this.marker = this.view.resizeMarker;
1932 this.proxy = this.view.resizeProxy;
1933 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
1934 'gridSplitters' + this.grid.getGridEl().id, {
1935 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
1937 this.scroll = false;
1938 this.hw = this.view.splitHandleWidth || 5;
1941 b4StartDrag : function(x, y){
1942 this.dragHeadersDisabled = this.view.headersDisabled;
1943 this.view.headersDisabled = true;
1944 var h = this.view.mainWrap.getHeight();
1945 this.marker.setHeight(h);
1947 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
1948 this.proxy.setHeight(h);
1949 var w = this.cm.getColumnWidth(this.cellIndex),
1950 minw = Math.max(w-this.grid.minColumnWidth, 0);
1951 this.resetConstraints();
1952 this.setXConstraint(minw, 1000);
1953 this.setYConstraint(0, 0);
1954 this.minX = x - minw;
1955 this.maxX = x + 1000;
1957 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
1960 allowHeaderDrag : function(e){
1964 handleMouseDown : function(e){
1965 var t = this.view.findHeaderCell(e.getTarget());
1966 if(t && this.allowHeaderDrag(e)){
1967 var xy = this.view.fly(t).getXY(),
1970 exy = e.getXY(), ex = exy[0],
1971 w = t.offsetWidth, adjust = false;
1973 if((ex - x) <= this.hw){
1975 }else if((x+w) - ex <= this.hw){
1978 if(adjust !== false){
1979 this.cm = this.grid.colModel;
1980 var ci = this.view.getCellIndex(t);
1982 if (ci + adjust < 0) {
1985 while(this.cm.isHidden(ci+adjust)){
1992 this.cellIndex = ci+adjust;
1994 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
1995 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
1997 }else if(this.view.columnDrag){
1998 this.view.columnDrag.callHandleMouseDown(e);
2003 endDrag : function(e){
2006 endX = Math.max(this.minX, e.getPageX()),
2007 diff = endX - this.startPos,
2008 disabled = this.dragHeadersDisabled;
2010 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
2011 setTimeout(function(){
2012 v.headersDisabled = disabled;
2016 autoOffset : function(){