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.3.0
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-markDirty"></div>/**
180 * @cfg {Boolean} markDirty True to show the dirty cell indicator when a cell has been modified. Defaults to <tt>true</tt>.
184 <div id="cfg-Ext.grid.GridView-cellSelectorDepth"></div>/**
185 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
187 cellSelectorDepth : 4,
189 <div id="cfg-Ext.grid.GridView-rowSelectorDepth"></div>/**
190 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
192 rowSelectorDepth : 10,
194 <div id="cfg-Ext.grid.GridView-rowBodySelectorDepth"></div>/**
195 * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
197 rowBodySelectorDepth : 10,
199 <div id="cfg-Ext.grid.GridView-cellSelector"></div>/**
200 * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
202 cellSelector : 'td.x-grid3-cell',
204 <div id="cfg-Ext.grid.GridView-rowSelector"></div>/**
205 * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
207 rowSelector : 'div.x-grid3-row',
209 <div id="cfg-Ext.grid.GridView-rowBodySelector"></div>/**
210 * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
212 rowBodySelector : 'div.x-grid3-row-body',
215 firstRowCls: 'x-grid3-row-first',
216 lastRowCls: 'x-grid3-row-last',
217 rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
219 <div id="cfg-Ext.grid.GridView-headerMenuOpenCls"></div>/**
220 * @cfg {String} headerMenuOpenCls The CSS class to add to the header cell when its menu is visible. Defaults to 'x-grid3-hd-menu-open'
222 headerMenuOpenCls: 'x-grid3-hd-menu-open',
224 <div id="cfg-Ext.grid.GridView-rowOverCls"></div>/**
225 * @cfg {String} rowOverCls The CSS class added to each row when it is hovered over. Defaults to 'x-grid3-row-over'
227 rowOverCls: 'x-grid3-row-over',
229 constructor : function(config) {
230 Ext.apply(this, config);
232 // These events are only used internally by the grid components
234 <div id="event-Ext.grid.GridView-beforerowremoved"></div>/**
235 * @event beforerowremoved
236 * Internal UI Event. Fired before a row is removed.
237 * @param {Ext.grid.GridView} view
238 * @param {Number} rowIndex The index of the row to be removed.
239 * @param {Ext.data.Record} record The Record to be removed
243 <div id="event-Ext.grid.GridView-beforerowsinserted"></div>/**
244 * @event beforerowsinserted
245 * Internal UI Event. Fired before rows are inserted.
246 * @param {Ext.grid.GridView} view
247 * @param {Number} firstRow The index of the first row to be inserted.
248 * @param {Number} lastRow The index of the last row to be inserted.
250 'beforerowsinserted',
252 <div id="event-Ext.grid.GridView-beforerefresh"></div>/**
253 * @event beforerefresh
254 * Internal UI Event. Fired before the view is refreshed.
255 * @param {Ext.grid.GridView} view
259 <div id="event-Ext.grid.GridView-rowremoved"></div>/**
261 * Internal UI Event. Fired after a row is removed.
262 * @param {Ext.grid.GridView} view
263 * @param {Number} rowIndex The index of the row that was removed.
264 * @param {Ext.data.Record} record The Record that was removed
268 <div id="event-Ext.grid.GridView-rowsinserted"></div>/**
269 * @event rowsinserted
270 * Internal UI Event. Fired after rows are inserted.
271 * @param {Ext.grid.GridView} view
272 * @param {Number} firstRow The index of the first inserted.
273 * @param {Number} lastRow The index of the last row inserted.
277 <div id="event-Ext.grid.GridView-rowupdated"></div>/**
279 * Internal UI Event. Fired after a row has been updated.
280 * @param {Ext.grid.GridView} view
281 * @param {Number} firstRow The index of the row updated.
282 * @param {Ext.data.record} record The Record backing the row updated.
286 <div id="event-Ext.grid.GridView-refresh"></div>/**
288 * Internal UI Event. Fired after the GridView's body has been refreshed.
289 * @param {Ext.grid.GridView} view
294 Ext.grid.GridView.superclass.constructor.call(this);
297 /* -------------------------------- UI Specific ----------------------------- */
299 <div id="prop-Ext.grid.GridView-Ext.Template"></div>/**
300 * The master template to use when rendering the GridView. Has a default template
301 * @property Ext.Template
304 masterTpl: new Ext.Template(
305 '<div class="x-grid3" hidefocus="true">',
306 '<div class="x-grid3-viewport">',
307 '<div class="x-grid3-header">',
308 '<div class="x-grid3-header-inner">',
309 '<div class="x-grid3-header-offset" style="{ostyle}">{header}</div>',
311 '<div class="x-clear"></div>',
313 '<div class="x-grid3-scroller">',
314 '<div class="x-grid3-body" style="{bstyle}">{body}</div>',
315 '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
318 '<div class="x-grid3-resize-marker"> </div>',
319 '<div class="x-grid3-resize-proxy"> </div>',
323 <div id="prop-Ext.grid.GridView-headerTpl"></div>/**
324 * The template to use when rendering headers. Has a default template
325 * @property headerTpl
328 headerTpl: new Ext.Template(
329 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
331 '<tr class="x-grid3-hd-row">{cells}</tr>',
336 <div id="prop-Ext.grid.GridView-bodyTpl"></div>/**
337 * The template to use when rendering the body. Has a default template
341 bodyTpl: new Ext.Template('{rows}'),
343 <div id="prop-Ext.grid.GridView-cellTpl"></div>/**
344 * The template to use to render each cell. Has a default template
348 cellTpl: new Ext.Template(
349 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
350 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
356 * Provides default templates if they are not given for this particular instance. Most of the templates are defined on
357 * the prototype, the ones defined inside this function are done so because they are based on Grid or GridView configuration
359 initTemplates : function() {
360 var templates = this.templates || {},
363 headerCellTpl = new Ext.Template(
364 '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
365 '<div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
366 this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
368 '<img alt="" class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
374 '<tr class="x-grid3-row-body-tr" style="{bodyStyle}">',
375 '<td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on">',
376 '<div class="x-grid3-row-body">{body}</div>',
382 '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
385 this.enableRowBody ? rowBodyText : '',
390 Ext.applyIf(templates, {
391 hcell : headerCellTpl,
394 header : this.headerTpl,
395 master : this.masterTpl,
396 row : new Ext.Template('<div class="x-grid3-row {alt}" style="{tstyle}">' + innerText + '</div>'),
397 rowInner: new Ext.Template(innerText)
400 for (name in templates) {
401 template = templates[name];
403 if (template && Ext.isFunction(template.compile) && !template.compiled) {
404 template.disableFormats = true;
409 this.templates = templates;
410 this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
415 * Each GridView has its own private flyweight, accessed through this method
418 if (!this._flyweight) {
419 this._flyweight = new Ext.Element.Flyweight(document.body);
421 this._flyweight.dom = el;
422 return this._flyweight;
426 getEditorParent : function() {
427 return this.scroller.dom;
432 * Finds and stores references to important elements
434 initElements : function() {
435 var Element = Ext.Element,
436 el = Ext.get(this.grid.getGridEl().dom.firstChild),
437 mainWrap = new Element(el.child('div.x-grid3-viewport')),
438 mainHd = new Element(mainWrap.child('div.x-grid3-header')),
439 scroller = new Element(mainWrap.child('div.x-grid3-scroller'));
441 if (this.grid.hideHeaders) {
442 mainHd.setDisplayed(false);
446 scroller.setStyle('overflow-x', 'hidden');
449 <div id="prop-Ext.grid.GridView-mainBody"></div>/**
450 * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
451 * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
461 innerHd : mainHd.child('div.x-grid3-header-inner').dom,
462 mainBody: new Element(Element.fly(scroller).child('div.x-grid3-body')),
463 focusEl : new Element(Element.fly(scroller).child('a')),
465 resizeMarker: new Element(el.child('div.x-grid3-resize-marker')),
466 resizeProxy : new Element(el.child('div.x-grid3-resize-proxy'))
469 this.focusEl.swallowEvent('click', true);
473 getRows : function() {
474 return this.hasRows() ? this.mainBody.dom.childNodes : [];
477 // finder methods, used with delegation
480 findCell : function(el) {
484 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
487 <div id="method-Ext.grid.GridView-findCellIndex"></div>/**
488 * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
489 * See also {@link #findRowIndex}
490 * @param {HTMLElement} el The target element
491 * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
493 findCellIndex : function(el, requiredCls) {
494 var cell = this.findCell(el),
498 hasCls = this.fly(cell).hasClass(requiredCls);
499 if (!requiredCls || hasCls) {
500 return this.getCellIndex(cell);
507 getCellIndex : function(el) {
509 var match = el.className.match(this.colRe);
511 if (match && match[1]) {
512 return this.cm.getIndexById(match[1]);
519 findHeaderCell : function(el) {
520 var cell = this.findCell(el);
521 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
525 findHeaderIndex : function(el){
526 return this.findCellIndex(el, this.hdCls);
529 <div id="method-Ext.grid.GridView-findRow"></div>/**
530 * Return the HtmlElement representing the grid row which contains the passed element.
531 * @param {HTMLElement} el The target HTMLElement
532 * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
534 findRow : function(el) {
538 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
541 <div id="method-Ext.grid.GridView-findRowIndex"></div>/**
542 * Return the index of the grid row which contains the passed HTMLElement.
543 * See also {@link #findCellIndex}
544 * @param {HTMLElement} el The target HTMLElement
545 * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
547 findRowIndex : function(el) {
548 var row = this.findRow(el);
549 return row ? row.rowIndex : false;
552 <div id="method-Ext.grid.GridView-findRowBody"></div>/**
553 * Return the HtmlElement representing the grid row body which contains the passed element.
554 * @param {HTMLElement} el The target HTMLElement
555 * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
557 findRowBody : function(el) {
562 return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
565 // getter methods for fetching elements dynamically in the grid
567 <div id="method-Ext.grid.GridView-getRow"></div>/**
568 * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
569 * @param {Number} index The row index
570 * @return {HtmlElement} The div element.
572 getRow : function(row) {
573 return this.getRows()[row];
576 <div id="method-Ext.grid.GridView-getCell"></div>/**
577 * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
578 * @param {Number} row The row index in which to find the cell.
579 * @param {Number} col The column index of the cell.
580 * @return {HtmlElement} The td at the specified coordinates.
582 getCell : function(row, col) {
583 return Ext.fly(this.getRow(row)).query(this.cellSelector)[col];
586 <div id="method-Ext.grid.GridView-getHeaderCell"></div>/**
587 * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
588 * @param {Number} index The column index
589 * @return {HtmlElement} The td element.
591 getHeaderCell : function(index) {
592 return this.mainHd.dom.getElementsByTagName('td')[index];
595 // manipulating elements
597 // private - use getRowClass to apply custom row classes
598 addRowClass : function(rowId, cls) {
599 var row = this.getRow(rowId);
601 this.fly(row).addClass(cls);
606 removeRowClass : function(row, cls) {
607 var r = this.getRow(row);
609 this.fly(r).removeClass(cls);
614 removeRow : function(row) {
615 Ext.removeNode(this.getRow(row));
616 this.syncFocusEl(row);
620 removeRows : function(firstRow, lastRow) {
621 var bd = this.mainBody.dom,
624 for (rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
625 Ext.removeNode(bd.childNodes[firstRow]);
628 this.syncFocusEl(firstRow);
631 /* ----------------------------------- Scrolling functions -------------------------------------------*/
634 getScrollState : function() {
635 var sb = this.scroller.dom;
644 restoreScroll : function(state) {
645 var sb = this.scroller.dom;
646 sb.scrollLeft = state.left;
647 sb.scrollTop = state.top;
650 <div id="method-Ext.grid.GridView-scrollToTop"></div>/**
651 * Scrolls the grid to the top
653 scrollToTop : function() {
654 var dom = this.scroller.dom;
661 syncScroll : function() {
662 this.syncHeaderScroll();
663 var mb = this.scroller.dom;
664 this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
668 syncHeaderScroll : function() {
669 var innerHd = this.innerHd,
670 scrollLeft = this.scroller.dom.scrollLeft;
672 innerHd.scrollLeft = scrollLeft;
673 innerHd.scrollLeft = scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
678 * Ensures the given column has the given icon class
680 updateSortIcon : function(col, dir) {
681 var sortClasses = this.sortClasses,
682 sortClass = sortClasses[dir == "DESC" ? 1 : 0],
683 headers = this.mainHd.select('td').removeClass(sortClasses);
685 headers.item(col).addClass(sortClass);
690 * Updates the size of every column and cell in the grid
692 updateAllColumnWidths : function() {
693 var totalWidth = this.getTotalWidth(),
694 colCount = this.cm.getColumnCount(),
695 rows = this.getRows(),
696 rowCount = rows.length,
698 row, rowFirstChild, trow, i, j;
700 for (i = 0; i < colCount; i++) {
701 widths[i] = this.getColumnWidth(i);
702 this.getHeaderCell(i).style.width = widths[i];
705 this.updateHeaderWidth();
707 for (i = 0; i < rowCount; i++) {
709 row.style.width = totalWidth;
710 rowFirstChild = row.firstChild;
713 rowFirstChild.style.width = totalWidth;
714 trow = rowFirstChild.rows[0];
716 for (j = 0; j < colCount; j++) {
717 trow.childNodes[j].style.width = widths[j];
722 this.onAllColumnWidthsUpdated(widths, totalWidth);
727 * Called after a column's width has been updated, this resizes all of the cells for that column in each row
728 * @param {Number} column The column index
730 updateColumnWidth : function(column, width) {
731 var columnWidth = this.getColumnWidth(column),
732 totalWidth = this.getTotalWidth(),
733 headerCell = this.getHeaderCell(column),
734 nodes = this.getRows(),
735 nodeCount = nodes.length,
738 this.updateHeaderWidth();
739 headerCell.style.width = columnWidth;
741 for (i = 0; i < nodeCount; i++) {
743 firstChild = row.firstChild;
745 row.style.width = totalWidth;
747 firstChild.style.width = totalWidth;
748 firstChild.rows[0].childNodes[column].style.width = columnWidth;
752 this.onColumnWidthUpdated(column, columnWidth, totalWidth);
757 * Sets the hidden status of a given column.
758 * @param {Number} col The column index
759 * @param {Boolean} hidden True to make the column hidden
761 updateColumnHidden : function(col, hidden) {
762 var totalWidth = this.getTotalWidth(),
763 display = hidden ? 'none' : '',
764 headerCell = this.getHeaderCell(col),
765 nodes = this.getRows(),
766 nodeCount = nodes.length,
767 row, rowFirstChild, i;
769 this.updateHeaderWidth();
770 headerCell.style.display = display;
772 for (i = 0; i < nodeCount; i++) {
774 row.style.width = totalWidth;
775 rowFirstChild = row.firstChild;
778 rowFirstChild.style.width = totalWidth;
779 rowFirstChild.rows[0].childNodes[col].style.display = display;
783 this.onColumnHiddenUpdated(col, hidden, totalWidth);
784 delete this.lastViewWidth; //recalc
790 * Renders all of the rows to a string buffer and returns the string. This is called internally
791 * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM.
792 * @param {Array} columns The column data acquired from getColumnData.
793 * @param {Array} records The array of records to render
794 * @param {Ext.data.Store} store The store to render the rows from
795 * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of
796 * the rows so this is used to maintain logic for striping etc
797 * @param {Number} colCount The total number of columns in the column model
798 * @param {Boolean} stripe True to stripe the rows
799 * @return {String} A string containing the HTML for the rendered rows
801 doRender : function(columns, records, store, startRow, colCount, stripe) {
802 var templates = this.templates,
803 cellTemplate = templates.cell,
804 rowTemplate = templates.row,
806 tstyle = 'width:' + this.getTotalWidth() + ';',
810 rowParams = {tstyle: tstyle},
812 len = records.length,
815 record, i, j, rowIndex;
817 //build up each row's HTML
818 for (j = 0; j < len; j++) {
822 rowIndex = j + startRow;
824 //build up each column's HTML
825 for (i = 0; i < colCount; i++) {
829 meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
830 meta.attr = meta.cellAttr = '';
831 meta.style = column.style;
832 meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
834 if (Ext.isEmpty(meta.value)) {
835 meta.value = ' ';
838 if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
839 meta.css += ' x-grid3-dirty-cell';
842 colBuffer[colBuffer.length] = cellTemplate.apply(meta);
846 //set up row striping and row dirtiness CSS classes
847 if (stripe && ((rowIndex + 1) % 2 === 0)) {
848 alt[0] = 'x-grid3-row-alt';
852 alt[1] = ' x-grid3-dirty-row';
855 rowParams.cols = colCount;
857 if (this.getRowClass) {
858 alt[2] = this.getRowClass(record, rowIndex, rowParams, store);
861 rowParams.alt = alt.join(' ');
862 rowParams.cells = colBuffer.join('');
864 rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams);
867 return rowBuffer.join('');
872 * Adds CSS classes and rowIndex to each row
873 * @param {Number} startRow The row to start from (defaults to 0)
875 processRows : function(startRow, skipStripe) {
876 if (!this.ds || this.ds.getCount() < 1) {
880 var rows = this.getRows(),
881 length = rows.length,
884 skipStripe = skipStripe || !this.grid.stripeRows;
885 startRow = startRow || 0;
887 for (i = 0; i < length; i++) {
892 row.className = row.className.replace(this.rowClsRe, ' ');
893 if ((i + 1) % 2 === 0){
894 row.className += ' x-grid3-row-alt';
900 // add first/last-row classes
901 if (startRow === 0) {
902 Ext.fly(rows[0]).addClass(this.firstRowCls);
905 Ext.fly(rows[length - 1]).addClass(this.lastRowCls);
911 afterRender : function() {
912 if (!this.ds || !this.cm) {
916 this.mainBody.dom.innerHTML = this.renderBody() || ' ';
917 this.processRows(0, true);
919 if (this.deferEmptyText !== true) {
920 this.applyEmptyText();
923 this.grid.fireEvent('viewready', this.grid);
928 * This is always intended to be called after renderUI. Sets up listeners on the UI elements
929 * and sets up options like column menus, moving and resizing.
931 afterRenderUI: function() {
932 var grid = this.grid;
936 // get mousedowns early
937 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
941 mouseover: this.handleHdOver,
942 mouseout : this.handleHdOut,
943 mousemove: this.handleHdMove
946 this.scroller.on('scroll', this.syncScroll, this);
948 if (grid.enableColumnResize !== false) {
949 this.splitZone = new Ext.grid.GridView.SplitDragZone(grid, this.mainHd.dom);
952 if (grid.enableColumnMove) {
953 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(grid, this.innerHd);
954 this.columnDrop = new Ext.grid.HeaderDropZone(grid, this.mainHd.dom);
957 if (grid.enableHdMenu !== false) {
958 this.hmenu = new Ext.menu.Menu({id: grid.id + '-hctx'});
960 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
961 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
964 if (grid.enableColumnHide !== false) {
965 this.colMenu = new Ext.menu.Menu({id:grid.id + '-hcols-menu'});
968 beforeshow: this.beforeColMenuShow,
969 itemclick : this.handleHdMenuClick
971 this.hmenu.add('-', {
974 text: this.columnsText,
976 iconCls: 'x-cols-icon'
980 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
983 if (grid.trackMouseOver) {
986 mouseover: this.onRowOver,
987 mouseout : this.onRowOut
991 if (grid.enableDragDrop || grid.enableDrag) {
992 this.dragZone = new Ext.grid.GridDragZone(grid, {
993 ddGroup : grid.ddGroup || 'GridDD'
997 this.updateHeaderSortState();
1002 * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not
1003 * render rows from the store, just the surrounding UI elements.
1005 renderUI : function() {
1006 var templates = this.templates;
1008 return templates.master.apply({
1009 body : templates.body.apply({rows:' '}),
1010 header: this.renderHeaders(),
1011 ostyle: 'width:' + this.getOffsetWidth() + ';',
1012 bstyle: 'width:' + this.getTotalWidth() + ';'
1017 processEvent : function(name, e) {
1018 var target = e.getTarget(),
1020 header = this.findHeaderIndex(target),
1021 row, cell, col, body;
1023 grid.fireEvent(name, e);
1025 if (header !== false) {
1026 grid.fireEvent('header' + name, grid, header, e);
1028 row = this.findRowIndex(target);
1030 // Grid's value-added events must bubble correctly to allow cancelling via returning false: cell->column->row
1031 // We must allow a return of false at any of these levels to cancel the event processing.
1032 // Particularly allowing rowmousedown to be cancellable by prior handlers which need to prevent selection.
1033 if (row !== false) {
1034 cell = this.findCellIndex(target);
1035 if (cell !== false) {
1036 col = grid.colModel.getColumnAt(cell);
1037 if (grid.fireEvent('cell' + name, grid, row, cell, e) !== false) {
1038 if (!col || (col.processEvent && (col.processEvent(name, e, grid, row, cell) !== false))) {
1039 grid.fireEvent('row' + name, grid, row, e);
1043 if (grid.fireEvent('row' + name, grid, row, e) !== false) {
1044 (body = this.findRowBody(target)) && grid.fireEvent('rowbody' + name, grid, row, e);
1048 grid.fireEvent('container' + name, grid, e);
1055 * Sizes the grid's header and body elements
1057 layout : function(initial) {
1058 if (!this.mainBody) {
1059 return; // not rendered
1062 var grid = this.grid,
1063 gridEl = grid.getGridEl(),
1064 gridSize = gridEl.getSize(true),
1065 gridWidth = gridSize.width,
1066 gridHeight = gridSize.height,
1067 scroller = this.scroller,
1068 scrollStyle, headerHeight, scrollHeight;
1070 if (gridWidth < 20 || gridHeight < 20) {
1074 if (grid.autoHeight) {
1075 scrollStyle = scroller.dom.style;
1076 scrollStyle.overflow = 'visible';
1079 scrollStyle.position = 'static';
1082 this.el.setSize(gridWidth, gridHeight);
1084 headerHeight = this.mainHd.getHeight();
1085 scrollHeight = gridHeight - headerHeight;
1087 scroller.setSize(gridWidth, scrollHeight);
1090 this.innerHd.style.width = (gridWidth) + "px";
1094 if (this.forceFit || (initial === true && this.autoFill)) {
1095 if (this.lastViewWidth != gridWidth) {
1096 this.fitColumns(false, false);
1097 this.lastViewWidth = gridWidth;
1101 this.syncHeaderScroll();
1104 this.onLayout(gridWidth, scrollHeight);
1107 // template functions for subclasses and plugins
1108 // these functions include precalculated values
1109 onLayout : function(vw, vh) {
1113 onColumnWidthUpdated : function(col, w, tw) {
1117 onAllColumnWidthsUpdated : function(ws, tw) {
1121 onColumnHiddenUpdated : function(col, hidden, tw) {
1125 updateColumnText : function(col, text) {
1129 afterMove : function(colIndex) {
1133 /* ----------------------------------- Core Specific -------------------------------------------*/
1135 init : function(grid) {
1138 this.initTemplates();
1139 this.initData(grid.store, grid.colModel);
1144 getColumnId : function(index){
1145 return this.cm.getColumnId(index);
1149 getOffsetWidth : function() {
1150 return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
1154 getScrollOffset: function() {
1155 return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
1160 * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just
1162 * @return {String} Rendered header row
1164 renderHeaders : function() {
1165 var colModel = this.cm,
1166 templates = this.templates,
1167 headerTpl = templates.hcell,
1169 colCount = colModel.getColumnCount(),
1170 last = colCount - 1,
1174 for (i = 0; i < colCount; i++) {
1176 cssCls = 'x-grid3-cell-first ';
1178 cssCls = i == last ? 'x-grid3-cell-last ' : '';
1182 id : colModel.getColumnId(i),
1183 value : colModel.getColumnHeader(i) || '',
1184 style : this.getColumnStyle(i, true),
1186 tooltip: this.getColumnTooltip(i)
1189 if (colModel.config[i].align == 'right') {
1190 properties.istyle = 'padding-right: 16px;';
1192 delete properties.istyle;
1195 cells[i] = headerTpl.apply(properties);
1198 return templates.header.apply({
1199 cells : cells.join(""),
1200 tstyle: String.format("width: {0};", this.getTotalWidth())
1207 getColumnTooltip : function(i) {
1208 var tooltip = this.cm.getColumnTooltip(i);
1210 if (Ext.QuickTips.isEnabled()) {
1211 return 'ext:qtip="' + tooltip + '"';
1213 return 'title="' + tooltip + '"';
1221 beforeUpdate : function() {
1222 this.grid.stopEditing(true);
1227 * Re-renders the headers and ensures they are sized correctly
1229 updateHeaders : function() {
1230 this.innerHd.firstChild.innerHTML = this.renderHeaders();
1232 this.updateHeaderWidth(false);
1237 * Ensures that the header is sized to the total width available to it
1238 * @param {Boolean} updateMain True to update the mainBody's width also (defaults to true)
1240 updateHeaderWidth: function(updateMain) {
1241 var innerHdChild = this.innerHd.firstChild,
1242 totalWidth = this.getTotalWidth();
1244 innerHdChild.style.width = this.getOffsetWidth();
1245 innerHdChild.firstChild.style.width = totalWidth;
1247 if (updateMain !== false) {
1248 this.mainBody.dom.style.width = totalWidth;
1252 <div id="method-Ext.grid.GridView-focusRow"></div>/**
1253 * Focuses the specified row.
1254 * @param {Number} row The row index
1256 focusRow : function(row) {
1257 this.focusCell(row, 0, false);
1260 <div id="method-Ext.grid.GridView-focusCell"></div>/**
1261 * Focuses the specified cell.
1262 * @param {Number} row The row index
1263 * @param {Number} col The column index
1265 focusCell : function(row, col, hscroll) {
1266 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
1268 var focusEl = this.focusEl;
1273 focusEl.focus.defer(1, focusEl);
1279 * Finds the Elements corresponding to the given row and column indexes
1281 resolveCell : function(row, col, hscroll) {
1282 if (!Ext.isNumber(row)) {
1290 if (row < 0 || row >= this.ds.getCount()) {
1293 col = (col !== undefined ? col : 0);
1295 var rowEl = this.getRow(row),
1297 colCount = colModel.getColumnCount(),
1300 if (!(hscroll === false && col === 0)) {
1301 while (col < colCount && colModel.isHidden(col)) {
1305 cellEl = this.getCell(row, col);
1308 return {row: rowEl, cell: cellEl};
1313 * Returns the XY co-ordinates of a given row/cell resolution (see {@link #resolveCell})
1314 * @return {Array} X and Y coords
1316 getResolvedXY : function(resolved) {
1321 var cell = resolved.cell,
1325 return Ext.fly(cell).getXY();
1327 return [this.el.getX(), Ext.fly(row).getY()];
1333 * Moves the focus element to the x and y co-ordinates of the given row and column
1335 syncFocusEl : function(row, col, hscroll) {
1338 if (!Ext.isArray(xy)) {
1339 row = Math.min(row, Math.max(0, this.getRows().length-1));
1345 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
1348 this.focusEl.setXY(xy || this.scroller.getXY());
1354 ensureVisible : function(row, col, hscroll) {
1355 var resolved = this.resolveCell(row, col, hscroll);
1357 if (!resolved || !resolved.row) {
1361 var rowEl = resolved.row,
1362 cellEl = resolved.cell,
1363 c = this.scroller.dom,
1368 while (p && p != stop) {
1369 ctop += p.offsetTop;
1373 ctop -= this.mainHd.dom.offsetHeight;
1374 stop = parseInt(c.scrollTop, 10);
1376 var cbot = ctop + rowEl.offsetHeight,
1377 ch = c.clientHeight,
1383 } else if(cbot > sbot) {
1384 c.scrollTop = cbot-ch;
1387 if (hscroll !== false) {
1388 var cleft = parseInt(cellEl.offsetLeft, 10),
1389 cright = cleft + cellEl.offsetWidth,
1390 sleft = parseInt(c.scrollLeft, 10),
1391 sright = sleft + c.clientWidth;
1393 if (cleft < sleft) {
1394 c.scrollLeft = cleft;
1395 } else if(cright > sright) {
1396 c.scrollLeft = cright-c.clientWidth;
1400 return this.getResolvedXY(resolved);
1404 insertRows : function(dm, firstRow, lastRow, isUpdate) {
1405 var last = dm.getCount() - 1;
1406 if( !isUpdate && firstRow === 0 && lastRow >= last) {
1407 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1409 this.fireEvent('rowsinserted', this, firstRow, lastRow);
1412 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
1414 var html = this.renderRows(firstRow, lastRow),
1415 before = this.getRow(firstRow);
1418 Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
1420 Ext.DomHelper.insertHtml('beforeBegin', before, html);
1422 var r = this.getRow(last - 1);
1424 Ext.fly(r).removeClass(this.lastRowCls);
1426 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
1429 this.fireEvent('rowsinserted', this, firstRow, lastRow);
1430 this.processRows(firstRow);
1431 } else if (firstRow === 0 || firstRow >= last) {
1432 //ensure first/last row is kept after an update.
1433 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
1436 this.syncFocusEl(firstRow);
1441 * DEPRECATED - this doesn't appear to be called anywhere in the library, remove in 4.0.
1443 deleteRows : function(dm, firstRow, lastRow) {
1444 if (dm.getRowCount() < 1) {
1447 this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
1449 this.removeRows(firstRow, lastRow);
1451 this.processRows(firstRow);
1452 this.fireEvent('rowsdeleted', this, firstRow, lastRow);
1458 * Builds a CSS string for the given column index
1459 * @param {Number} colIndex The column index
1460 * @param {Boolean} isHeader True if getting the style for the column's header
1461 * @return {String} The CSS string
1463 getColumnStyle : function(colIndex, isHeader) {
1464 var colModel = this.cm,
1465 colConfig = colModel.config,
1466 style = isHeader ? '' : colConfig[colIndex].css || '',
1467 align = colConfig[colIndex].align;
1469 style += String.format("width: {0};", this.getColumnWidth(colIndex));
1471 if (colModel.isHidden(colIndex)) {
1472 style += 'display: none; ';
1476 style += String.format("text-align: {0};", align);
1484 * Returns the width of a given column minus its border width
1485 * @return {Number} The column index
1486 * @return {String|Number} The width in pixels
1488 getColumnWidth : function(column) {
1489 var columnWidth = this.cm.getColumnWidth(column),
1490 borderWidth = this.borderWidth;
1492 if (Ext.isNumber(columnWidth)) {
1493 if (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2)) {
1494 return columnWidth + "px";
1496 return Math.max(columnWidth - borderWidth, 0) + "px";
1505 * Returns the total width of all visible columns
1508 getTotalWidth : function() {
1509 return this.cm.getTotalWidth() + 'px';
1514 * Resizes each column to fit the available grid width.
1515 * TODO: The second argument isn't even used, remove it in 4.0
1516 * @param {Boolean} preventRefresh True to prevent resizing of each row to the new column sizes (defaults to false)
1517 * @param {null} onlyExpand NOT USED, will be removed in 4.0
1518 * @param {Number} omitColumn The index of a column to leave at its current width. Defaults to undefined
1519 * @return {Boolean} True if the operation succeeded, false if not or undefined if the grid view is not yet initialized
1521 fitColumns : function(preventRefresh, onlyExpand, omitColumn) {
1522 var grid = this.grid,
1524 totalColWidth = colModel.getTotalWidth(false),
1525 gridWidth = this.getGridInnerWidth(),
1526 extraWidth = gridWidth - totalColWidth,
1530 colWidth, fraction, i;
1532 // not initialized, so don't screw up the default widths
1533 if (gridWidth < 20 || extraWidth === 0) {
1537 var visibleColCount = colModel.getColumnCount(true),
1538 totalColCount = colModel.getColumnCount(false),
1539 adjCount = visibleColCount - (Ext.isNumber(omitColumn) ? 1 : 0);
1541 if (adjCount === 0) {
1543 omitColumn = undefined;
1546 //FIXME: the algorithm used here is odd and potentially confusing. Includes this for loop and the while after it.
1547 for (i = 0; i < totalColCount; i++) {
1548 if (!colModel.isFixed(i) && i !== omitColumn) {
1549 colWidth = colModel.getColumnWidth(i);
1550 columns.push(i, colWidth);
1552 if (!colModel.isHidden(i)) {
1559 fraction = (gridWidth - colModel.getTotalWidth()) / width;
1561 while (columns.length) {
1562 colWidth = columns.pop();
1565 colModel.setColumnWidth(i, Math.max(grid.minColumnWidth, Math.floor(colWidth + colWidth * fraction)), true);
1568 //this has been changed above so remeasure now
1569 totalColWidth = colModel.getTotalWidth(false);
1571 if (totalColWidth > gridWidth) {
1572 var adjustCol = (adjCount == visibleColCount) ? extraCol : omitColumn,
1573 newWidth = Math.max(1, colModel.getColumnWidth(adjustCol) - (totalColWidth - gridWidth));
1575 colModel.setColumnWidth(adjustCol, newWidth, true);
1578 if (preventRefresh !== true) {
1579 this.updateAllColumnWidths();
1587 * Resizes the configured autoExpandColumn to take the available width after the other columns have
1588 * been accounted for
1589 * @param {Boolean} preventUpdate True to prevent the resizing of all rows (defaults to false)
1591 autoExpand : function(preventUpdate) {
1592 var grid = this.grid,
1594 gridWidth = this.getGridInnerWidth(),
1595 totalColumnWidth = colModel.getTotalWidth(false),
1596 autoExpandColumn = grid.autoExpandColumn;
1598 if (!this.userResized && autoExpandColumn) {
1599 if (gridWidth != totalColumnWidth) {
1600 //if we are not already using all available width, resize the autoExpandColumn
1601 var colIndex = colModel.getIndexById(autoExpandColumn),
1602 currentWidth = colModel.getColumnWidth(colIndex),
1603 desiredWidth = gridWidth - totalColumnWidth + currentWidth,
1604 newWidth = Math.min(Math.max(desiredWidth, grid.autoExpandMin), grid.autoExpandMax);
1606 if (currentWidth != newWidth) {
1607 colModel.setColumnWidth(colIndex, newWidth, true);
1609 if (preventUpdate !== true) {
1610 this.updateColumnWidth(colIndex, newWidth);
1617 <div id="method-Ext.grid.GridView-getGridInnerWidth"></div>/**
1618 * Returns the total internal width available to the grid, taking the scrollbar into account
1619 * @return {Number} The total width
1621 getGridInnerWidth: function() {
1622 return this.grid.getGridEl().getWidth(true) - this.getScrollOffset();
1627 * Returns an array of column configurations - one for each column
1628 * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
1630 getColumnData : function() {
1633 colCount = colModel.getColumnCount(),
1634 fields = this.ds.fields,
1637 for (i = 0; i < colCount; i++) {
1638 name = colModel.getDataIndex(i);
1641 name : Ext.isDefined(name) ? name : (fields.get(i) ? fields.get(i).name : undefined),
1642 renderer: colModel.getRenderer(i),
1643 scope : colModel.getRendererScope(i),
1644 id : colModel.getColumnId(i),
1645 style : this.getColumnStyle(i)
1654 * Renders rows between start and end indexes
1655 * @param {Number} startRow Index of the first row to render
1656 * @param {Number} endRow Index of the last row to render
1658 renderRows : function(startRow, endRow) {
1659 var grid = this.grid,
1661 stripe = grid.stripeRows,
1662 colModel = grid.colModel,
1663 colCount = colModel.getColumnCount(),
1664 rowCount = store.getCount(),
1671 startRow = startRow || 0;
1672 endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
1673 records = store.getRange(startRow, endRow);
1675 return this.doRender(this.getColumnData(), records, store, startRow, colCount, stripe);
1679 renderBody : function(){
1680 var markup = this.renderRows() || ' ';
1681 return this.templates.body.apply({rows: markup});
1686 * Refreshes a row by re-rendering it. Fires the rowupdated event when done
1688 refreshRow: function(record) {
1689 var store = this.ds,
1690 colCount = this.cm.getColumnCount(),
1691 columns = this.getColumnData(),
1692 last = colCount - 1,
1693 cls = ['x-grid3-row'],
1695 tstyle: String.format("width: {0};", this.getTotalWidth())
1698 cellTpl = this.templates.cell,
1699 rowIndex, row, column, meta, css, i;
1701 if (Ext.isNumber(record)) {
1703 record = store.getAt(rowIndex);
1705 rowIndex = store.indexOf(record);
1708 //the record could not be found
1709 if (!record || rowIndex < 0) {
1713 //builds each column in this row
1714 for (i = 0; i < colCount; i++) {
1715 column = columns[i];
1718 css = 'x-grid3-cell-first';
1720 css = (i == last) ? 'x-grid3-cell-last ' : '';
1725 style : column.style,
1730 // Need to set this after, because we pass meta to the renderer
1731 meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
1733 if (Ext.isEmpty(meta.value)) {
1734 meta.value = ' ';
1737 if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
1738 meta.css += ' x-grid3-dirty-cell';
1741 colBuffer[i] = cellTpl.apply(meta);
1744 row = this.getRow(rowIndex);
1747 if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
1748 cls.push('x-grid3-row-alt');
1751 if (this.getRowClass) {
1752 rowParams.cols = colCount;
1753 cls.push(this.getRowClass(record, rowIndex, rowParams, store));
1756 this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
1757 rowParams.cells = colBuffer.join("");
1758 row.innerHTML = this.templates.rowInner.apply(rowParams);
1760 this.fireEvent('rowupdated', this, rowIndex, record);
1763 <div id="method-Ext.grid.GridView-refresh"></div>/**
1764 * Refreshs the grid UI
1765 * @param {Boolean} headersToo (optional) True to also refresh the headers
1767 refresh : function(headersToo) {
1768 this.fireEvent('beforerefresh', this);
1769 this.grid.stopEditing(true);
1771 var result = this.renderBody();
1772 this.mainBody.update(result).setWidth(this.getTotalWidth());
1773 if (headersToo === true) {
1774 this.updateHeaders();
1775 this.updateHeaderSortState();
1777 this.processRows(0, true);
1779 this.applyEmptyText();
1780 this.fireEvent('refresh', this);
1785 * Displays the configured emptyText if there are currently no rows to display
1787 applyEmptyText : function() {
1788 if (this.emptyText && !this.hasRows()) {
1789 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1795 * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
1796 * if the sorting has changed since this function was last run.
1798 updateHeaderSortState : function() {
1799 var state = this.ds.getSortState();
1804 if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
1805 this.grid.fireEvent('sortchange', this.grid, state);
1808 this.sortState = state;
1810 var sortColumn = this.cm.findColumnIndex(state.field);
1811 if (sortColumn != -1) {
1812 var sortDir = state.direction;
1813 this.updateSortIcon(sortColumn, sortDir);
1819 * Removes any sorting indicator classes from the column headers
1821 clearHeaderSortState : function() {
1822 if (!this.sortState) {
1825 this.grid.fireEvent('sortchange', this.grid, null);
1826 this.mainHd.select('td').removeClass(this.sortClasses);
1827 delete this.sortState;
1832 * Destroys all objects associated with the GridView
1834 destroy : function() {
1837 gridEl = grid.getGridEl(),
1838 dragZone = me.dragZone,
1839 splitZone = me.splitZone,
1840 columnDrag = me.columnDrag,
1841 columnDrop = me.columnDrop,
1842 scrollToTopTask = me.scrollToTopTask,
1846 if (scrollToTopTask && scrollToTopTask.cancel) {
1847 scrollToTopTask.cancel();
1850 Ext.destroyMembers(me, 'colMenu', 'hmenu');
1852 me.initData(null, null);
1853 me.purgeListeners();
1855 Ext.fly(me.innerHd).un("click", me.handleHdDown, me);
1857 if (grid.enableColumnMove) {
1858 columnDragData = columnDrag.dragData;
1859 columnDragProxy = columnDrag.proxy;
1862 columnDragProxy.ghost,
1865 columnDrop.proxyTop,
1866 columnDrop.proxyBottom,
1867 columnDragData.ddel,
1868 columnDragData.header
1871 if (columnDragProxy.anim) {
1872 Ext.destroy(columnDragProxy.anim);
1875 delete columnDragProxy.ghost;
1876 delete columnDragData.ddel;
1877 delete columnDragData.header;
1878 columnDrag.destroy();
1880 delete Ext.dd.DDM.locationCache[columnDrag.id];
1881 delete columnDrag._domRef;
1883 delete columnDrop.proxyTop;
1884 delete columnDrop.proxyBottom;
1885 columnDrop.destroy();
1886 delete Ext.dd.DDM.locationCache["gridHeader" + gridEl.id];
1887 delete columnDrop._domRef;
1888 delete Ext.dd.DDM.ids[columnDrop.ddGroup];
1891 if (splitZone) { // enableColumnResize
1892 splitZone.destroy();
1893 delete splitZone._domRef;
1894 delete Ext.dd.DDM.ids["gridSplitters" + gridEl.id];
1897 Ext.fly(me.innerHd).removeAllListeners();
1898 Ext.removeNode(me.innerHd);
1916 delete grid.container;
1922 Ext.dd.DDM.currentTarget = null;
1923 delete Ext.dd.DDM.locationCache[gridEl.id];
1925 Ext.EventManager.removeResizeListener(me.onWindowResize, me);
1929 onDenyColumnHide : function() {
1934 render : function() {
1935 if (this.autoFill) {
1936 var ct = this.grid.ownerCt;
1938 if (ct && ct.getLayout()) {
1939 ct.on('afterlayout', function() {
1940 this.fitColumns(true, true);
1941 this.updateHeaders();
1942 this.updateHeaderSortState();
1943 }, this, {single: true});
1945 } else if (this.forceFit) {
1946 this.fitColumns(true, false);
1947 } else if (this.grid.autoExpandColumn) {
1948 this.autoExpand(true);
1951 this.grid.getGridEl().dom.innerHTML = this.renderUI();
1953 this.afterRenderUI();
1956 /* --------------------------------- Model Events and Handlers --------------------------------*/
1960 * Binds a new Store and ColumnModel to this GridView. Removes any listeners from the old objects (if present)
1961 * and adds listeners to the new ones
1962 * @param {Ext.data.Store} newStore The new Store instance
1963 * @param {Ext.grid.ColumnModel} newColModel The new ColumnModel instance
1965 initData : function(newStore, newColModel) {
1969 var oldStore = me.ds;
1971 oldStore.un('add', me.onAdd, me);
1972 oldStore.un('load', me.onLoad, me);
1973 oldStore.un('clear', me.onClear, me);
1974 oldStore.un('remove', me.onRemove, me);
1975 oldStore.un('update', me.onUpdate, me);
1976 oldStore.un('datachanged', me.onDataChange, me);
1978 if (oldStore !== newStore && oldStore.autoDestroy) {
1988 remove : me.onRemove,
1989 update : me.onUpdate,
1991 datachanged: me.onDataChange
1996 var oldColModel = me.cm;
1998 oldColModel.un('configchange', me.onColConfigChange, me);
1999 oldColModel.un('widthchange', me.onColWidthChange, me);
2000 oldColModel.un('headerchange', me.onHeaderChange, me);
2001 oldColModel.un('hiddenchange', me.onHiddenChange, me);
2002 oldColModel.un('columnmoved', me.onColumnMove, me);
2006 delete me.lastViewWidth;
2010 configchange: me.onColConfigChange,
2011 widthchange : me.onColWidthChange,
2012 headerchange: me.onHeaderChange,
2013 hiddenchange: me.onHiddenChange,
2014 columnmoved : me.onColumnMove
2019 me.cm = newColModel;
2023 onDataChange : function(){
2025 this.updateHeaderSortState();
2026 this.syncFocusEl(0);
2030 onClear : function() {
2032 this.syncFocusEl(0);
2036 onUpdate : function(store, record) {
2037 this.refreshRow(record);
2041 onAdd : function(store, records, index) {
2042 this.insertRows(store, index, index + (records.length-1));
2046 onRemove : function(store, record, index, isUpdate) {
2047 if (isUpdate !== true) {
2048 this.fireEvent('beforerowremoved', this, index, record);
2051 this.removeRow(index);
2053 if (isUpdate !== true) {
2054 this.processRows(index);
2055 this.applyEmptyText();
2056 this.fireEvent('rowremoved', this, index, record);
2062 * Called when a store is loaded, scrolls to the top row
2064 onLoad : function() {
2066 if (!this.scrollToTopTask) {
2067 this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
2069 this.scrollToTopTask.delay(1);
2076 onColWidthChange : function(cm, col, width) {
2077 this.updateColumnWidth(col, width);
2081 onHeaderChange : function(cm, col, text) {
2082 this.updateHeaders();
2086 onHiddenChange : function(cm, col, hidden) {
2087 this.updateColumnHidden(col, hidden);
2091 onColumnMove : function(cm, oldIndex, newIndex) {
2092 this.indexMap = null;
2094 this.restoreScroll(this.getScrollState());
2096 this.afterMove(newIndex);
2097 this.grid.fireEvent('columnmove', oldIndex, newIndex);
2101 onColConfigChange : function() {
2102 delete this.lastViewWidth;
2103 this.indexMap = null;
2107 /* -------------------- UI Events and Handlers ------------------------------ */
2109 initUI : function(grid) {
2110 grid.on('headerclick', this.onHeaderClick, this);
2114 initEvents : Ext.emptyFn,
2117 onHeaderClick : function(g, index) {
2118 if (this.headersDisabled || !this.cm.isSortable(index)) {
2121 g.stopEditing(true);
2122 g.store.sort(this.cm.getDataIndex(index));
2127 * Adds the hover class to a row when hovered over
2129 onRowOver : function(e, target) {
2130 var row = this.findRowIndex(target);
2132 if (row !== false) {
2133 this.addRowClass(row, this.rowOverCls);
2139 * Removes the hover class from a row on mouseout
2141 onRowOut : function(e, target) {
2142 var row = this.findRowIndex(target);
2144 if (row !== false && !e.within(this.getRow(row), true)) {
2145 this.removeRowClass(row, this.rowOverCls);
2150 onRowSelect : function(row) {
2151 this.addRowClass(row, this.selectedRowClass);
2155 onRowDeselect : function(row) {
2156 this.removeRowClass(row, this.selectedRowClass);
2160 onCellSelect : function(row, col) {
2161 var cell = this.getCell(row, col);
2163 this.fly(cell).addClass('x-grid3-cell-selected');
2168 onCellDeselect : function(row, col) {
2169 var cell = this.getCell(row, col);
2171 this.fly(cell).removeClass('x-grid3-cell-selected');
2176 handleWheel : function(e) {
2177 e.stopPropagation();
2182 * Called by the SplitDragZone when a drag has been completed. Resizes the columns
2184 onColumnSplitterMoved : function(cellIndex, width) {
2185 this.userResized = true;
2186 this.grid.colModel.setColumnWidth(cellIndex, width, true);
2188 if (this.forceFit) {
2189 this.fitColumns(true, false, cellIndex);
2190 this.updateAllColumnWidths();
2192 this.updateColumnWidth(cellIndex, width);
2193 this.syncHeaderScroll();
2196 this.grid.fireEvent('columnresize', cellIndex, width);
2201 * Click handler for the shared column dropdown menu, called on beforeshow. Builds the menu
2202 * which displays the list of columns for the user to show or hide.
2204 beforeColMenuShow : function() {
2205 var colModel = this.cm,
2206 colCount = colModel.getColumnCount(),
2207 colMenu = this.colMenu,
2210 colMenu.removeAll();
2212 for (i = 0; i < colCount; i++) {
2213 if (colModel.config[i].hideable !== false) {
2214 colMenu.add(new Ext.menu.CheckItem({
2215 text : colModel.getColumnHeader(i),
2216 itemId : 'col-' + colModel.getColumnId(i),
2217 checked : !colModel.isHidden(i),
2218 disabled : colModel.config[i].hideable === false,
2227 * Attached as the 'itemclick' handler to the header menu and the column show/hide submenu (if available).
2228 * Performs sorting if the sorter buttons were clicked, otherwise hides/shows the column that was clicked.
2230 handleHdMenuClick : function(item) {
2231 var store = this.ds,
2232 dataIndex = this.cm.getDataIndex(this.hdCtxIndex);
2234 switch (item.getItemId()) {
2236 store.sort(dataIndex, 'ASC');
2239 store.sort(dataIndex, 'DESC');
2242 this.handleHdMenuClickDefault(item);
2247 <div id="method-Ext.grid.GridView-handleHdMenuClickDefault"></div>/**
2248 * Called by handleHdMenuClick if any button except a sort ASC/DESC button was clicked. The default implementation provides
2249 * the column hide/show functionality based on the check state of the menu item. A different implementation can be provided
2251 * @param {Ext.menu.BaseItem} item The menu item that was clicked
2253 handleHdMenuClickDefault: function(item) {
2254 var colModel = this.cm,
2255 itemId = item.getItemId(),
2256 index = colModel.getIndexById(itemId.substr(4));
2259 if (item.checked && colModel.getColumnsBy(this.isHideableColumn, this).length <= 1) {
2260 this.onDenyColumnHide();
2263 colModel.setHidden(index, item.checked);
2269 * Called when a header cell is clicked - shows the menu if the click happened over a trigger button
2271 handleHdDown : function(e, target) {
2272 if (Ext.fly(target).hasClass('x-grid3-hd-btn')) {
2275 var colModel = this.cm,
2276 header = this.findHeaderCell(target),
2277 index = this.getCellIndex(header),
2278 sortable = colModel.isSortable(index),
2280 menuItems = menu.items,
2281 menuCls = this.headerMenuOpenCls;
2283 this.hdCtxIndex = index;
2285 Ext.fly(header).addClass(menuCls);
2286 menuItems.get('asc').setDisabled(!sortable);
2287 menuItems.get('desc').setDisabled(!sortable);
2289 menu.on('hide', function() {
2290 Ext.fly(header).removeClass(menuCls);
2291 }, this, {single:true});
2293 menu.show(target, 'tl-bl?');
2299 * Attached to the headers' mousemove event. This figures out the CSS cursor to use based on where the mouse is currently
2300 * pointed. If the mouse is currently hovered over the extreme left or extreme right of any header cell and the cell next
2301 * to it is resizable it is given the resize cursor, otherwise the cursor is set to an empty string.
2303 handleHdMove : function(e) {
2304 var header = this.findHeaderCell(this.activeHdRef);
2306 if (header && !this.headersDisabled) {
2307 var handleWidth = this.splitHandleWidth || 5,
2308 activeRegion = this.activeHdRegion,
2309 headerStyle = header.style,
2312 pageX = e.getPageX();
2314 if (this.grid.enableColumnResize !== false) {
2315 var activeHeaderIndex = this.activeHdIndex,
2316 previousVisible = this.getPreviousVisible(activeHeaderIndex),
2317 currentResizable = colModel.isResizable(activeHeaderIndex),
2318 previousResizable = previousVisible && colModel.isResizable(previousVisible),
2319 inLeftResizer = pageX - activeRegion.left <= handleWidth,
2320 inRightResizer = activeRegion.right - pageX <= (!this.activeHdBtn ? handleWidth : 2);
2322 if (inLeftResizer && previousResizable) {
2323 cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
2324 } else if (inRightResizer && currentResizable) {
2325 cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
2329 headerStyle.cursor = cursor;
2335 * Returns the index of the nearest currently visible header to the left of the given index.
2336 * @param {Number} index The header index
2337 * @return {Number/undefined} The index of the nearest visible header
2339 getPreviousVisible: function(index) {
2341 if (!this.cm.isHidden(index - 1)) {
2351 * Tied to the header element's mouseover event - adds the over class to the header cell if the menu is not disabled
2354 handleHdOver : function(e, target) {
2355 var header = this.findHeaderCell(target);
2357 if (header && !this.headersDisabled) {
2358 var fly = this.fly(header);
2360 this.activeHdRef = target;
2361 this.activeHdIndex = this.getCellIndex(header);
2362 this.activeHdRegion = fly.getRegion();
2364 if (!this.isMenuDisabled(this.activeHdIndex, fly)) {
2365 fly.addClass('x-grid3-hd-over');
2366 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
2368 if (this.activeHdBtn) {
2369 this.activeHdBtn.dom.style.height = (header.firstChild.offsetHeight - 1) + 'px';
2377 * Tied to the header element's mouseout event. Removes the hover class from the header cell
2379 handleHdOut : function(e, target) {
2380 var header = this.findHeaderCell(target);
2382 if (header && (!Ext.isIE || !e.within(header, true))) {
2383 this.activeHdRef = null;
2384 this.fly(header).removeClass('x-grid3-hd-over');
2385 header.style.cursor = '';
2391 * Used by {@link #handleHdOver} to determine whether or not to show the header menu class on cell hover
2392 * @param {Number} cellIndex The header cell index
2393 * @param {Ext.Element} el The cell element currently being hovered over
2395 isMenuDisabled: function(cellIndex, el) {
2396 return this.cm.isMenuDisabled(cellIndex);
2401 * Returns true if there are any rows rendered into the GridView
2402 * @return {Boolean} True if any rows have been rendered
2404 hasRows : function() {
2405 var fc = this.mainBody.dom.firstChild;
2406 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
2412 isHideableColumn : function(c) {
2418 * DEPRECATED - will be removed in Ext JS 5.0
2420 bind : function(d, c) {
2421 this.initData(d, c);
2427 // This is a support class used internally by the Grid components
2428 Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
2430 constructor: function(grid, hd){
2432 this.view = grid.getView();
2433 this.marker = this.view.resizeMarker;
2434 this.proxy = this.view.resizeProxy;
2435 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
2436 'gridSplitters' + this.grid.getGridEl().id, {
2437 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
2439 this.scroll = false;
2440 this.hw = this.view.splitHandleWidth || 5;
2443 b4StartDrag : function(x, y){
2444 this.dragHeadersDisabled = this.view.headersDisabled;
2445 this.view.headersDisabled = true;
2446 var h = this.view.mainWrap.getHeight();
2447 this.marker.setHeight(h);
2449 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
2450 this.proxy.setHeight(h);
2451 var w = this.cm.getColumnWidth(this.cellIndex),
2452 minw = Math.max(w-this.grid.minColumnWidth, 0);
2453 this.resetConstraints();
2454 this.setXConstraint(minw, 1000);
2455 this.setYConstraint(0, 0);
2456 this.minX = x - minw;
2457 this.maxX = x + 1000;
2459 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
2462 allowHeaderDrag : function(e){
2466 handleMouseDown : function(e){
2467 var t = this.view.findHeaderCell(e.getTarget());
2468 if(t && this.allowHeaderDrag(e)){
2469 var xy = this.view.fly(t).getXY(),
2476 if((ex - x) <= this.hw){
2478 }else if((x+w) - ex <= this.hw){
2481 if(adjust !== false){
2482 this.cm = this.grid.colModel;
2483 var ci = this.view.getCellIndex(t);
2485 if (ci + adjust < 0) {
2488 while(this.cm.isHidden(ci+adjust)){
2495 this.cellIndex = ci+adjust;
2497 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
2498 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
2500 }else if(this.view.columnDrag){
2501 this.view.columnDrag.callHandleMouseDown(e);
2506 endDrag : function(e){
2509 endX = Math.max(this.minX, e.getPageX()),
2510 diff = endX - this.startPos,
2511 disabled = this.dragHeadersDisabled;
2513 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
2514 setTimeout(function(){
2515 v.headersDisabled = disabled;
2519 autoOffset : function(){