X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..10a866c12701c0a0afd0ac85dcdcf32a421514ac:/src/widgets/grid/GridView.js?ds=sidebyside diff --git a/src/widgets/grid/GridView.js b/src/widgets/grid/GridView.js index a290de34..407b7aa6 100644 --- a/src/widgets/grid/GridView.js +++ b/src/widgets/grid/GridView.js @@ -1,5 +1,5 @@ /*! - * Ext JS Library 3.0.0 + * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license @@ -15,67 +15,7 @@ * @constructor * @param {Object} config */ -Ext.grid.GridView = function(config){ - Ext.apply(this, config); - // These events are only used internally by the grid components - this.addEvents( - /** - * @event beforerowremoved - * Internal UI Event. Fired before a row is removed. - * @param {Ext.grid.GridView} view - * @param {Number} rowIndex The index of the row to be removed. - * @param {Ext.data.Record} record The Record to be removed - */ - "beforerowremoved", - /** - * @event beforerowsinserted - * Internal UI Event. Fired before rows are inserted. - * @param {Ext.grid.GridView} view - * @param {Number} firstRow The index of the first row to be inserted. - * @param {Number} lastRow The index of the last row to be inserted. - */ - "beforerowsinserted", - /** - * @event beforerefresh - * Internal UI Event. Fired before the view is refreshed. - * @param {Ext.grid.GridView} view - */ - "beforerefresh", - /** - * @event rowremoved - * Internal UI Event. Fired after a row is removed. - * @param {Ext.grid.GridView} view - * @param {Number} rowIndex The index of the row that was removed. - * @param {Ext.data.Record} record The Record that was removed - */ - "rowremoved", - /** - * @event rowsinserted - * Internal UI Event. Fired after rows are inserted. - * @param {Ext.grid.GridView} view - * @param {Number} firstRow The index of the first inserted. - * @param {Number} lastRow The index of the last row inserted. - */ - "rowsinserted", - /** - * @event rowupdated - * Internal UI Event. Fired after a row has been updated. - * @param {Ext.grid.GridView} view - * @param {Number} firstRow The index of the row updated. - * @param {Ext.data.record} record The Record backing the row updated. - */ - "rowupdated", - /** - * @event refresh - * Internal UI Event. Fired after the GridView's body has been refreshed. - * @param {Ext.grid.GridView} view - */ - "refresh" - ); - Ext.grid.GridView.superclass.constructor.call(this); -}; - -Ext.extend(Ext.grid.GridView, Ext.util.Observable, { +Ext.grid.GridView = Ext.extend(Ext.util.Observable, { /** * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom * parameters to the row template for the current row to customize how it is rendered using the rowParams @@ -153,9 +93,10 @@ viewConfig: { deferEmptyText : true, /** * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar - * (defaults to 19 pixels). + * (defaults to undefined). If an explicit value isn't specified, this will be automatically + * calculated. */ - scrollOffset : 19, + scrollOffset : undefined, /** * @cfg {Boolean} autoFill * Defaults to false. Specify true to have the column widths re-proportioned @@ -176,24 +117,24 @@ viewConfig: { */ forceFit : false, /** - * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to ["sort-asc", "sort-desc"]) + * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to ['sort-asc', 'sort-desc']) */ - sortClasses : ["sort-asc", "sort-desc"], + sortClasses : ['sort-asc', 'sort-desc'], /** - * @cfg {String} sortAscText The text displayed in the "Sort Ascending" menu item (defaults to "Sort Ascending") + * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to 'Sort Ascending') */ - sortAscText : "Sort Ascending", + sortAscText : 'Sort Ascending', /** - * @cfg {String} sortDescText The text displayed in the "Sort Descending" menu item (defaults to "Sort Descending") + * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to 'Sort Descending') */ - sortDescText : "Sort Descending", + sortDescText : 'Sort Descending', /** - * @cfg {String} columnsText The text displayed in the "Columns" menu item (defaults to "Columns") + * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to 'Columns') */ - columnsText : "Columns", + columnsText : 'Columns', /** - * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to "x-grid3-row-selected"). An + * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to 'x-grid3-row-selected'). An * example overriding the default styling:
.x-grid3-row-selected {background-color: yellow;}
@@ -207,7 +148,7 @@ viewConfig: {
* @type String
*/
- selectedRowClass : "x-grid3-row-selected",
+ selectedRowClass : 'x-grid3-row-selected',
// private
borderWidth : 2,
@@ -223,6 +164,11 @@ viewConfig: {
* @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to 10)
*/
rowSelectorDepth : 10,
+
+ /**
+ * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to 10)
+ */
+ rowBodySelectorDepth : 10,
/**
* @cfg {String} cellSelector The selector used to find cells internally (defaults to 'td.x-grid3-cell')
@@ -233,10 +179,75 @@ viewConfig: {
*/
rowSelector : 'div.x-grid3-row',
+ /**
+ * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to 'div.x-grid3-row')
+ */
+ rowBodySelector : 'div.x-grid3-row-body',
+
// private
firstRowCls: 'x-grid3-row-first',
lastRowCls: 'x-grid3-row-last',
rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
+
+ constructor : function(config){
+ Ext.apply(this, config);
+ // These events are only used internally by the grid components
+ this.addEvents(
+ /**
+ * @event beforerowremoved
+ * Internal UI Event. Fired before a row is removed.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} rowIndex The index of the row to be removed.
+ * @param {Ext.data.Record} record The Record to be removed
+ */
+ 'beforerowremoved',
+ /**
+ * @event beforerowsinserted
+ * Internal UI Event. Fired before rows are inserted.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} firstRow The index of the first row to be inserted.
+ * @param {Number} lastRow The index of the last row to be inserted.
+ */
+ 'beforerowsinserted',
+ /**
+ * @event beforerefresh
+ * Internal UI Event. Fired before the view is refreshed.
+ * @param {Ext.grid.GridView} view
+ */
+ 'beforerefresh',
+ /**
+ * @event rowremoved
+ * Internal UI Event. Fired after a row is removed.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} rowIndex The index of the row that was removed.
+ * @param {Ext.data.Record} record The Record that was removed
+ */
+ 'rowremoved',
+ /**
+ * @event rowsinserted
+ * Internal UI Event. Fired after rows are inserted.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} firstRow The index of the first inserted.
+ * @param {Number} lastRow The index of the last row inserted.
+ */
+ 'rowsinserted',
+ /**
+ * @event rowupdated
+ * Internal UI Event. Fired after a row has been updated.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} firstRow The index of the row updated.
+ * @param {Ext.data.record} record The Record backing the row updated.
+ */
+ 'rowupdated',
+ /**
+ * @event refresh
+ * Internal UI Event. Fired after the GridView's body has been refreshed.
+ * @param {Ext.grid.GridView} view
+ */
+ 'refresh'
+ );
+ Ext.grid.GridView.superclass.constructor.call(this);
+ },
/* -------------------------------- UI Specific ----------------------------- */
@@ -295,14 +306,14 @@ viewConfig: {
for(var k in ts){
var t = ts[k];
- if(t && typeof t.compile == 'function' && !t.compiled){
+ if(t && Ext.isFunction(t.compile) && !t.compiled){
t.disableFormats = true;
t.compile();
}
}
this.templates = ts;
- this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");
+ this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
},
// private
@@ -349,7 +360,7 @@ viewConfig: {
this.mainBody = new E(this.scroller.dom.firstChild);
this.focusEl = new E(this.scroller.dom.childNodes[1]);
- this.focusEl.swallowEvent("click", true);
+ this.focusEl.swallowEvent('click', true);
this.resizeMarker = new E(cs[1]);
this.resizeProxy = new E(cs[2]);
@@ -370,12 +381,12 @@ viewConfig: {
return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
},
-/**
- * Return the index of the grid column which contains the passed element.
- * See also {@link #findRowIndex} - * @param {Element} el The target element - * @return The column index, or false if the target element is not within a row of this GridView. - */ + /** + *Return the index of the grid column which contains the passed HTMLElement.
+ * See also {@link #findRowIndex} + * @param {HTMLElement} el The target element + * @return {Number} The column index, or false if the target element is not within a row of this GridView. + */ findCellIndex : function(el, requiredCls){ var cell = this.findCell(el); if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){ @@ -406,11 +417,11 @@ viewConfig: { return this.findCellIndex(el, this.hdCls); }, -/** - * Return the HtmlElement representing the grid row which contains the passed element. - * @param {Element} el The target element - * @return The row element, or null if the target element is not within a row of this GridView. - */ + /** + * Return the HtmlElement representing the grid row which contains the passed element. + * @param {HTMLElement} el The target HTMLElement + * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView. + */ findRow : function(el){ if(!el){ return false; @@ -418,43 +429,55 @@ viewConfig: { return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth); }, -/** - *Return the index of the grid row which contains the passed element.
- * See also {@link #findCellIndex} - * @param {Element} el The target element - * @return The row index, or false if the target element is not within a row of this GridView. - */ + /** + *Return the index of the grid row which contains the passed HTMLElement.
+ * See also {@link #findCellIndex} + * @param {HTMLElement} el The target HTMLElement + * @return {Number} The row index, or false if the target element is not within a row of this GridView. + */ findRowIndex : function(el){ var r = this.findRow(el); return r ? r.rowIndex : false; }, + + /** + * Return the HtmlElement representing the grid row body which contains the passed element. + * @param {HTMLElement} el The target HTMLElement + * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView. + */ + findRowBody : function(el){ + if(!el){ + return false; + } + return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth); + }, // getter methods for fetching elements dynamically in the grid -/** - * Return the <div> HtmlElement which represents a Grid row for the specified index. - * @param {Number} index The row index - * @return {HtmlElement} The div element. - */ + /** + * Return the <div> HtmlElement which represents a Grid row for the specified index. + * @param {Number} index The row index + * @return {HtmlElement} The div element. + */ getRow : function(row){ return this.getRows()[row]; }, -/** - * Returns the grid's <td> HtmlElement at the specified coordinates. - * @param {Number} row The row index in which to find the cell. - * @param {Number} col The column index of the cell. - * @return {HtmlElement} The td at the specified coordinates. - */ + /** + * Returns the grid's <td> HtmlElement at the specified coordinates. + * @param {Number} row The row index in which to find the cell. + * @param {Number} col The column index of the cell. + * @return {HtmlElement} The td at the specified coordinates. + */ getCell : function(row, col){ return this.getRow(row).getElementsByTagName('td')[col]; }, -/** - * Return the <td> HtmlElement which represents the Grid's header cell for the specified column index. - * @param {Number} index The column index - * @return {HtmlElement} The td element. - */ + /** + * Return the <td> HtmlElement which represents the Grid's header cell for the specified column index. + * @param {Number} index The column index + * @return {HtmlElement} The td element. + */ getHeaderCell : function(index){ return this.mainHd.dom.getElementsByTagName('td')[index]; }, @@ -519,7 +542,7 @@ viewConfig: { syncScroll : function(){ this.syncHeaderScroll(); var mb = this.scroller.dom; - this.grid.fireEvent("bodyscroll", mb.scrollLeft, mb.scrollTop); + this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop); }, // private @@ -533,7 +556,7 @@ viewConfig: { updateSortIcon : function(col, dir){ var sc = this.sortClasses; var hds = this.mainHd.select('td').removeClass(sc); - hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]); + hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]); }, // private @@ -632,33 +655,33 @@ viewConfig: { c = cs[i]; p.id = c.id; p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : ''); - p.attr = p.cellAttr = ""; - p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds); + p.attr = p.cellAttr = ''; + p.value = c.renderer.call(c.scope, r.data[c.name], p, r, rowIndex, i, ds); p.style = c.style; if(Ext.isEmpty(p.value)){ - p.value = " "; + p.value = ' '; } - if(this.markDirty && r.dirty && typeof r.modified[c.name] !== 'undefined'){ + if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){ p.css += ' x-grid3-dirty-cell'; } cb[cb.length] = ct.apply(p); } var alt = []; if(stripe && ((rowIndex+1) % 2 === 0)){ - alt[0] = "x-grid3-row-alt"; + alt[0] = 'x-grid3-row-alt'; } if(r.dirty){ - alt[1] = " x-grid3-dirty-row"; + alt[1] = ' x-grid3-dirty-row'; } rp.cols = colCount; if(this.getRowClass){ alt[2] = this.getRowClass(r, rowIndex, rp, ds); } - rp.alt = alt.join(" "); - rp.cells = cb.join(""); + rp.alt = alt.join(' '); + rp.cells = cb.join(''); buf[buf.length] = rt.apply(rp); } - return buf.join(""); + return buf.join(''); }, // private @@ -666,16 +689,24 @@ viewConfig: { if(!this.ds || this.ds.getCount() < 1){ return; } - var rows = this.getRows(); + var rows = this.getRows(), + len = rows.length, + i, r; + skipStripe = skipStripe || !this.grid.stripeRows; startRow = startRow || 0; - Ext.each(rows, function(row, idx){ - row.rowIndex = idx; - row.className = row.className.replace(this.rowClsRe, ' '); - if (!skipStripe && (idx + 1) % 2 === 0) { - row.className += ' x-grid3-row-alt'; - } - }); + for(i = 0; i