X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..6e39d509471fe9b4e2660e0d1631b350d0c66f40:/docs/source/GroupingView.html diff --git a/docs/source/GroupingView.html b/docs/source/GroupingView.html index 5d0d995b..fe1ba17e 100644 --- a/docs/source/GroupingView.html +++ b/docs/source/GroupingView.html @@ -1,17 +1,12 @@ - - - The source code - - - - -
/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-
/** + + + + The source code + + + + +
/** * @class Ext.grid.GroupingView * @extends Ext.grid.GridView * Adds the ability for single level grouping to the grid. A {@link Ext.data.GroupingStore GroupingStore} @@ -146,13 +141,13 @@ var grid = new Ext.grid.GridPanel({ *
*/ groupTextTpl : '{text}', - +
/** * @cfg {String} groupMode Indicates how to construct the group identifier. 'value' constructs the id using * raw value, 'display' constructs the id using the rendered value. Defaults to 'value'. */ groupMode: 'value', - +
/** * @cfg {Function} groupRenderer This property must be configured in the {@link Ext.grid.Column} for * each column. @@ -178,6 +173,10 @@ var grid = new Ext.grid.GridPanel({ ); } this.startGroup.compile(); + if(!this.endGroup){ + this.endGroup = ''; + } + this.endGroup = ''; }, @@ -231,7 +230,7 @@ var grid = new Ext.grid.GridPanel({ } if((item = items.get('showGroups'))){ item.setDisabled(disabled); - item.setChecked(!!this.getGroupField(), true); + item.setChecked(this.enableGrouping, true); } }, @@ -252,7 +251,7 @@ var grid = new Ext.grid.GridPanel({ this.hmenu.add({ itemId:'showGroups', text: this.showGroupsText, - checked: true, + checked: true, checkHandler: this.onShowGroupsClick, scope: this }); @@ -261,14 +260,34 @@ var grid = new Ext.grid.GridPanel({ } }, + processEvent: function(name, e){ + var hd = e.getTarget('.x-grid-group-hd', this.mainBody); + if(hd){ + // group value is at the end of the string + var field = this.getGroupField(), + prefix = this.getPrefix(field), + groupValue = hd.id.substring(prefix.length); + + // remove trailing '-hd' + groupValue = groupValue.substr(0, groupValue.length - 3); + if(groupValue){ + this.grid.fireEvent('group' + name, this.grid, field, groupValue, e); + } + } + + }, + // private onGroupByClick : function(){ + this.enableGrouping = true; this.grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex)); this.beforeMenuShow(); // Make sure the checkboxes get properly set when changing groups + this.refresh(); }, // private onShowGroupsClick : function(mi, checked){ + this.enableGrouping = checked; if(checked){ this.onGroupByClick(); }else{ @@ -276,20 +295,34 @@ var grid = new Ext.grid.GridPanel({ } }, +
/** + * Toggle the group that contains the specific row. + * @param {Number} rowIndex The row inside the group + * @param {Boolean} expanded (optional) + */ + toggleRowIndex : function(rowIndex, expanded){ + if(!this.enableGrouping){ + return; + } + var row = this.getRow(rowIndex); + if(row){ + this.toggleGroup(this.findGroup(row), expanded); + } + }, +
/** * Toggles the specified group if no value is passed, otherwise sets the expanded state of the group to the value passed. * @param {String} groupId The groupId assigned to the group (see getGroupId) * @param {Boolean} expanded (optional) */ toggleGroup : function(group, expanded){ - this.grid.stopEditing(true); - group = Ext.getDom(group); - var gel = Ext.fly(group); - expanded = expanded !== undefined ? - expanded : gel.hasClass('x-grid-group-collapsed'); - - this.state[gel.dom.id] = expanded; - gel[expanded ? 'removeClass' : 'addClass']('x-grid-group-collapsed'); + var gel = Ext.get(group); + expanded = Ext.isDefined(expanded) ? expanded : gel.hasClass('x-grid-group-collapsed'); + if(this.state[gel.id] !== expanded){ + this.grid.stopEditing(true); + this.state[gel.id] = expanded; + gel[expanded ? 'removeClass' : 'addClass']('x-grid-group-collapsed'); + } },
/** @@ -339,7 +372,7 @@ var grid = new Ext.grid.GridPanel({ getGroupField : function(){ return this.grid.store.getGroupState(); }, - + // private afterRender : function(){ Ext.grid.GroupingView.superclass.afterRender.call(this); @@ -354,15 +387,16 @@ var grid = new Ext.grid.GridPanel({ var eg = !!groupField; // if they turned off grouping and the last grouped field is hidden if(this.hideGroupedColumn) { - var colIndex = this.cm.findColumnIndex(groupField); - if(!eg && this.lastGroupField !== undefined) { + var colIndex = this.cm.findColumnIndex(groupField), + hasLastGroupField = Ext.isDefined(this.lastGroupField); + if(!eg && hasLastGroupField){ this.mainBody.update(''); this.cm.setHidden(this.cm.findColumnIndex(this.lastGroupField), false); delete this.lastGroupField; - }else if (eg && this.lastGroupField === undefined) { + }else if (eg && !hasLastGroupField){ this.lastGroupField = groupField; this.cm.setHidden(colIndex, true); - }else if (eg && this.lastGroupField !== undefined && groupField !== this.lastGroupField) { + }else if (eg && hasLastGroupField && groupField !== this.lastGroupField) { this.mainBody.update(''); var oldIndex = this.cm.findColumnIndex(this.lastGroupField); this.cm.setHidden(oldIndex, false); @@ -383,14 +417,13 @@ var grid = new Ext.grid.GridPanel({ colIndex = this.cm.findColumnIndex(groupField), g; - this.enableGrouping = !!groupField; + this.enableGrouping = (this.enableGrouping === false) ? false : !!groupField; if(!this.enableGrouping || this.isUpdating){ return Ext.grid.GroupingView.superclass.doRender.apply( this, arguments); } var gstyle = 'width:' + this.getTotalWidth() + ';', - gidPrefix = this.grid.getGridEl().id, cfg = this.cm.config[colIndex], groupRenderer = cfg.groupRenderer || cfg.renderer, prefix = this.showGroupName ? (cfg.groupName || cfg.header)+': ' : '', @@ -401,14 +434,13 @@ var grid = new Ext.grid.GridPanel({ var rowIndex = startRow + i, r = rs[i], gvalue = r.data[groupField]; - + g = this.getGroup(gvalue, r, groupRenderer, rowIndex, colIndex, ds); if(!curGroup || curGroup.group != g){ - gid = this.constructId(gvalue, gidPrefix, groupField, colIndex); - // if state is defined use it, however state is in terms of expanded - // so negate it, otherwise use the default. - var isCollapsed = typeof this.state[gid] !== 'undefined' ? !this.state[gid] : this.startCollapsed; - var gcls = isCollapsed ? 'x-grid-group-collapsed' : ''; + gid = this.constructId(gvalue, groupField, colIndex); + // if state is defined use it, however state is in terms of expanded + // so negate it, otherwise use the default. + this.state[gid] = !(Ext.isDefined(this.state[gid]) ? !this.state[gid] : this.startCollapsed); curGroup = { group: g, gvalue: gvalue, @@ -416,7 +448,7 @@ var grid = new Ext.grid.GridPanel({ groupId: gid, startRow: rowIndex, rs: [r], - cls: gcls, + cls: this.state[gid] ? '' : 'x-grid-group-collapsed', style: gstyle }; groups.push(curGroup); @@ -445,16 +477,21 @@ var grid = new Ext.grid.GridPanel({ */ getGroupId : function(value){ var field = this.getGroupField(); - return this.constructId(value, this.grid.getGridEl().id, field, this.cm.findColumnIndex(field)); + return this.constructId(value, field, this.cm.findColumnIndex(field)); }, - + // private - constructId : function(value, prefix, field, idx){ + constructId : function(value, field, idx){ var cfg = this.cm.config[idx], groupRenderer = cfg.groupRenderer || cfg.renderer, val = (this.groupMode == 'value') ? value : this.getGroup(value, {data:{}}, groupRenderer, 0, idx, this.ds); - - return prefix + '-gp-' + field + '-' + Ext.util.Format.htmlEncode(val); + + return this.getPrefix(field) + Ext.util.Format.htmlEncode(val); + }, + + // private + getPrefix: function(field){ + return this.grid.getGridEl().id + '-gp-' + field + '-'; }, // private @@ -520,17 +557,10 @@ var grid = new Ext.grid.GridPanel({ // private onBeforeRowSelect : function(sm, rowIndex){ - if(!this.enableGrouping){ - return; - } - var row = this.getRow(rowIndex); - if(row && !row.offsetParent){ - var g = this.findGroup(row); - this.toggleGroup(g, true); - } + this.toggleRowIndex(rowIndex, true); } }); // private -Ext.grid.GroupingView.GROUP_ID = 1000;
- +Ext.grid.GroupingView.GROUP_ID = 1000; + \ No newline at end of file