Created
June 6, 2009 04:38
-
-
Save ryanbriones/124695 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Override Ext.grid.GroupingView to provide a workaround to group | |
| // by a column that isn't being displayed | |
| // | |
| // Based on ExtJS 3.0 RC2 | |
| // | |
| // OR | |
| // | |
| // you could do it the right way and pass | |
| // {hideGroupedColumn: true, showGroupName: false} | |
| // to your Ext.grid.GroupingView | |
| // whoops! file under: not obvious. | |
| Ext.override(Ext.grid.GroupingView, { | |
| doRender : function(cs, rs, ds, startRow, colCount, stripe){ | |
| if(rs.length < 1){ | |
| return ''; | |
| } | |
| var groupField = this.getGroupField(); | |
| var colIndex = this.cm.findColumnIndex(groupField); | |
| this.enableGrouping = !!groupField; | |
| if(!this.enableGrouping || this.isUpdating){ | |
| return Ext.grid.GroupingView.superclass.doRender.apply( | |
| this, arguments); | |
| } | |
| var gstyle = 'width:'+this.getTotalWidth()+';'; | |
| var gidPrefix = this.grid.getGridEl().id; | |
| // WORKAROUND | |
| if(colIndex > 0) { | |
| var cfg = this.cm.config[colIndex]; | |
| var groupRenderer = cfg.groupRenderer || cfg.renderer; | |
| var prefix = this.showGroupName ? | |
| (cfg.groupName || cfg.header)+': ' : ''; | |
| } else { | |
| var groupRenderer = null; | |
| var prefix = ''; | |
| } | |
| var groups = [], curGroup, i, len, gid; | |
| for(i = 0, len = rs.length; i < len; i++){ | |
| var rowIndex = startRow + i; | |
| var r = rs[i], | |
| gvalue = r.data[groupField], | |
| g = this.getGroup(gvalue, r, groupRenderer, rowIndex, colIndex, ds); | |
| if(!curGroup || curGroup.group != g){ | |
| gid = gidPrefix + '-gp-' + groupField + '-' + Ext.util.Format.htmlEncode(g); | |
| // 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' : ''; | |
| curGroup = { | |
| group: g, | |
| gvalue: gvalue, | |
| text: prefix + g, | |
| groupId: gid, | |
| startRow: rowIndex, | |
| rs: [r], | |
| cls: gcls, | |
| style: gstyle | |
| }; | |
| groups.push(curGroup); | |
| }else{ | |
| curGroup.rs.push(r); | |
| } | |
| r._groupId = gid; | |
| } | |
| var buf = []; | |
| for(i = 0, len = groups.length; i < len; i++){ | |
| var g = groups[i]; | |
| this.doGroupStart(buf, g, cs, ds, colCount); | |
| buf[buf.length] = Ext.grid.GroupingView.superclass.doRender.call( | |
| this, cs, g.rs, ds, g.startRow, colCount, stripe); | |
| this.doGroupEnd(buf, g, cs, ds, colCount); | |
| } | |
| return buf.join(''); | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment