You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

624 lines
22 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
2 years ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.grid.GroupingView
  17. * @extends Ext.grid.GridView
  18. * Adds the ability for single level grouping to the grid. A {@link Ext.data.GroupingStore GroupingStore}
  19. * must be used to enable grouping. Some grouping characteristics may also be configured at the
  20. * {@link Ext.grid.Column Column level}<div class="mdetail-params"><ul>
  21. * <li><code>{@link Ext.grid.Column#emptyGroupText emptyGroupText}</code></li>
  22. * <li><code>{@link Ext.grid.Column#groupable groupable}</code></li>
  23. * <li><code>{@link Ext.grid.Column#groupName groupName}</code></li>
  24. * <li><code>{@link Ext.grid.Column#groupRender groupRender}</code></li>
  25. * </ul></div>
  26. * <p>Sample usage:</p>
  27. * <pre><code>
  28. var grid = new Ext.grid.GridPanel({
  29. // A groupingStore is required for a GroupingView
  30. store: new {@link Ext.data.GroupingStore}({
  31. autoDestroy: true,
  32. reader: reader,
  33. data: xg.dummyData,
  34. sortInfo: {field: 'company', direction: 'ASC'},
  35. {@link Ext.data.GroupingStore#groupOnSort groupOnSort}: true,
  36. {@link Ext.data.GroupingStore#remoteGroup remoteGroup}: true,
  37. {@link Ext.data.GroupingStore#groupField groupField}: 'industry'
  38. }),
  39. colModel: new {@link Ext.grid.ColumnModel}({
  40. columns:[
  41. {id:'company',header: 'Company', width: 60, dataIndex: 'company'},
  42. // {@link Ext.grid.Column#groupable groupable}, {@link Ext.grid.Column#groupName groupName}, {@link Ext.grid.Column#groupRender groupRender} are also configurable at column level
  43. {header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price', {@link Ext.grid.Column#groupable groupable}: false},
  44. {header: 'Change', dataIndex: 'change', renderer: Ext.util.Format.usMoney},
  45. {header: 'Industry', dataIndex: 'industry'},
  46. {header: 'Last Updated', renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  47. ],
  48. defaults: {
  49. sortable: true,
  50. menuDisabled: false,
  51. width: 20
  52. }
  53. }),
  54. view: new Ext.grid.GroupingView({
  55. {@link Ext.grid.GridView#forceFit forceFit}: true,
  56. // custom grouping text template to display the number of items per group
  57. {@link #groupTextTpl}: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
  58. }),
  59. frame:true,
  60. width: 700,
  61. height: 450,
  62. collapsible: true,
  63. animCollapse: false,
  64. title: 'Grouping Example',
  65. iconCls: 'icon-grid',
  66. renderTo: document.body
  67. });
  68. * </code></pre>
  69. * @constructor
  70. * @param {Object} config
  71. */
  72. Ext.grid.GroupingView = Ext.extend(Ext.grid.GridView, {
  73. /**
  74. * @cfg {String} groupByText Text displayed in the grid header menu for grouping by a column
  75. * (defaults to 'Group By This Field').
  76. */
  77. groupByText : 'Group By This Field',
  78. /**
  79. * @cfg {String} showGroupsText Text displayed in the grid header for enabling/disabling grouping
  80. * (defaults to 'Show in Groups').
  81. */
  82. showGroupsText : 'Show in Groups',
  83. /**
  84. * @cfg {Boolean} hideGroupedColumn <tt>true</tt> to hide the column that is currently grouped (defaults to <tt>false</tt>)
  85. */
  86. hideGroupedColumn : false,
  87. /**
  88. * @cfg {Boolean} showGroupName If <tt>true</tt> will display a prefix plus a ': ' before the group field value
  89. * in the group header line. The prefix will consist of the <tt><b>{@link Ext.grid.Column#groupName groupName}</b></tt>
  90. * (or the configured <tt><b>{@link Ext.grid.Column#header header}</b></tt> if not provided) configured in the
  91. * {@link Ext.grid.Column} for each set of grouped rows (defaults to <tt>true</tt>).
  92. */
  93. showGroupName : true,
  94. /**
  95. * @cfg {Boolean} startCollapsed <tt>true</tt> to start all groups collapsed (defaults to <tt>false</tt>)
  96. */
  97. startCollapsed : false,
  98. /**
  99. * @cfg {Boolean} enableGrouping <tt>false</tt> to disable grouping functionality (defaults to <tt>true</tt>)
  100. */
  101. enableGrouping : true,
  102. /**
  103. * @cfg {Boolean} enableGroupingMenu <tt>true</tt> to enable the grouping control in the column menu (defaults to <tt>true</tt>)
  104. */
  105. enableGroupingMenu : true,
  106. /**
  107. * @cfg {Boolean} enableNoGroups <tt>true</tt> to allow the user to turn off grouping (defaults to <tt>true</tt>)
  108. */
  109. enableNoGroups : true,
  110. /**
  111. * @cfg {String} emptyGroupText The text to display when there is an empty group value (defaults to <tt>'(None)'</tt>).
  112. * May also be specified per column, see {@link Ext.grid.Column}.{@link Ext.grid.Column#emptyGroupText emptyGroupText}.
  113. */
  114. emptyGroupText : '(None)',
  115. /**
  116. * @cfg {Boolean} ignoreAdd <tt>true</tt> to skip refreshing the view when new rows are added (defaults to <tt>false</tt>)
  117. */
  118. ignoreAdd : false,
  119. /**
  120. * @cfg {String} groupTextTpl The template used to render the group header (defaults to <tt>'{text}'</tt>).
  121. * This is used to format an object which contains the following properties:
  122. * <div class="mdetail-params"><ul>
  123. * <li><b>group</b> : String<p class="sub-desc">The <i>rendered</i> value of the group field.
  124. * By default this is the unchanged value of the group field. If a <tt><b>{@link Ext.grid.Column#groupRenderer groupRenderer}</b></tt>
  125. * is specified, it is the result of a call to that function.</p></li>
  126. * <li><b>gvalue</b> : Object<p class="sub-desc">The <i>raw</i> value of the group field.</p></li>
  127. * <li><b>text</b> : String<p class="sub-desc">The configured header (as described in <tt>{@link #showGroupName})</tt>
  128. * if <tt>{@link #showGroupName}</tt> is <tt>true</tt>) plus the <i>rendered</i> group field value.</p></li>
  129. * <li><b>groupId</b> : String<p class="sub-desc">A unique, generated ID which is applied to the
  130. * View Element which contains the group.</p></li>
  131. * <li><b>startRow</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>
  132. * <li><b>rs</b> : Array<p class="sub-desc">Contains a single element: The Record providing the data
  133. * for the row which caused group change.</p></li>
  134. * <li><b>cls</b> : String<p class="sub-desc">The generated class name string to apply to the group header Element.</p></li>
  135. * <li><b>style</b> : String<p class="sub-desc">The inline style rules to apply to the group header Element.</p></li>
  136. * </ul></div></p>
  137. * See {@link Ext.XTemplate} for information on how to format data using a template. Possible usage:<pre><code>
  138. var grid = new Ext.grid.GridPanel({
  139. ...
  140. view: new Ext.grid.GroupingView({
  141. groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
  142. }),
  143. });
  144. * </code></pre>
  145. */
  146. groupTextTpl : '{text}',
  147. /**
  148. * @cfg {String} groupMode Indicates how to construct the group identifier. <tt>'value'</tt> constructs the id using
  149. * raw value, <tt>'display'</tt> constructs the id using the rendered value. Defaults to <tt>'value'</tt>.
  150. */
  151. groupMode: 'value',
  152. /**
  153. * @cfg {Function} groupRenderer This property must be configured in the {@link Ext.grid.Column} for
  154. * each column.
  155. */
  156. /**
  157. * @cfg {Boolean} cancelEditOnToggle True to cancel any editing when the group header is toggled. Defaults to <tt>true</tt>.
  158. */
  159. cancelEditOnToggle: true,
  160. // private
  161. initTemplates : function(){
  162. Ext.grid.GroupingView.superclass.initTemplates.call(this);
  163. this.state = {};
  164. var sm = this.grid.getSelectionModel();
  165. sm.on(sm.selectRow ? 'beforerowselect' : 'beforecellselect',
  166. this.onBeforeRowSelect, this);
  167. if(!this.startGroup){
  168. this.startGroup = new Ext.XTemplate(
  169. '<div id="{groupId}" class="x-grid-group {cls}">',
  170. '<div id="{groupId}-hd" class="x-grid-group-hd" style="{style}"><div class="x-grid-group-title">', this.groupTextTpl ,'</div></div>',
  171. '<div id="{groupId}-bd" class="x-grid-group-body">'
  172. );
  173. }
  174. this.startGroup.compile();
  175. if (!this.endGroup) {
  176. this.endGroup = '</div></div>';
  177. }
  178. },
  179. // private
  180. findGroup : function(el){
  181. return Ext.fly(el).up('.x-grid-group', this.mainBody.dom);
  182. },
  183. // private
  184. getGroups : function(){
  185. return this.hasRows() ? this.mainBody.dom.childNodes : [];
  186. },
  187. // private
  188. onAdd : function(ds, records, index) {
  189. if (this.canGroup() && !this.ignoreAdd) {
  190. var ss = this.getScrollState();
  191. this.fireEvent('beforerowsinserted', ds, index, index + (records.length-1));
  192. this.refresh();
  193. this.restoreScroll(ss);
  194. this.fireEvent('rowsinserted', ds, index, index + (records.length-1));
  195. } else if (!this.canGroup()) {
  196. Ext.grid.GroupingView.superclass.onAdd.apply(this, arguments);
  197. }
  198. },
  199. // private
  200. onRemove : function(ds, record, index, isUpdate){
  201. Ext.grid.GroupingView.superclass.onRemove.apply(this, arguments);
  202. var g = document.getElementById(record._groupId);
  203. if(g && g.childNodes[1].childNodes.length < 1){
  204. Ext.removeNode(g);
  205. }
  206. this.applyEmptyText();
  207. },
  208. // private
  209. refreshRow : function(record){
  210. if(this.ds.getCount()==1){
  211. this.refresh();
  212. }else{
  213. this.isUpdating = true;
  214. Ext.grid.GroupingView.superclass.refreshRow.apply(this, arguments);
  215. this.isUpdating = false;
  216. }
  217. },
  218. // private
  219. beforeMenuShow : function(){
  220. var item, items = this.hmenu.items, disabled = this.cm.config[this.hdCtxIndex].groupable === false;
  221. if((item = items.get('groupBy'))){
  222. item.setDisabled(disabled);
  223. }
  224. if((item = items.get('showGroups'))){
  225. item.setDisabled(disabled);
  226. item.setChecked(this.canGroup(), true);
  227. }
  228. },
  229. // private
  230. renderUI : function(){
  231. var markup = Ext.grid.GroupingView.superclass.renderUI.call(this);
  232. if(this.enableGroupingMenu && this.hmenu){
  233. this.hmenu.add('-',{
  234. itemId:'groupBy',
  235. text: this.groupByText,
  236. handler: this.onGroupByClick,
  237. scope: this,
  238. iconCls:'x-group-by-icon'
  239. });
  240. if(this.enableNoGroups){
  241. this.hmenu.add({
  242. itemId:'showGroups',
  243. text: this.showGroupsText,
  244. checked: true,
  245. checkHandler: this.onShowGroupsClick,
  246. scope: this
  247. });
  248. }
  249. this.hmenu.on('beforeshow', this.beforeMenuShow, this);
  250. }
  251. return markup;
  252. },
  253. processEvent: function(name, e){
  254. Ext.grid.GroupingView.superclass.processEvent.call(this, name, e);
  255. var hd = e.getTarget('.x-grid-group-hd', this.mainBody);
  256. if(hd){
  257. // group value is at the end of the string
  258. var field = this.getGroupField(),
  259. prefix = this.getPrefix(field),
  260. groupValue = hd.id.substring(prefix.length),
  261. emptyRe = new RegExp('gp-' + Ext.escapeRe(field) + '--hd');
  262. // remove trailing '-hd'
  263. groupValue = groupValue.substr(0, groupValue.length - 3);
  264. // also need to check for empty groups
  265. if(groupValue || emptyRe.test(hd.id)){
  266. this.grid.fireEvent('group' + name, this.grid, field, groupValue, e);
  267. }
  268. if(name == 'mousedown' && e.button == 0){
  269. this.toggleGroup(hd.parentNode);
  270. }
  271. }
  272. },
  273. // private
  274. onGroupByClick : function(){
  275. var grid = this.grid;
  276. this.enableGrouping = true;
  277. grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex));
  278. grid.fireEvent('groupchange', grid, grid.store.getGroupState());
  279. this.beforeMenuShow(); // Make sure the checkboxes get properly set when changing groups
  280. this.refresh();
  281. },
  282. // private
  283. onShowGroupsClick : function(mi, checked){
  284. this.enableGrouping = checked;
  285. if(checked){
  286. this.onGroupByClick();
  287. }else{
  288. this.grid.store.clearGrouping();
  289. this.grid.fireEvent('groupchange', this, null);
  290. }
  291. },
  292. /**
  293. * Toggle the group that contains the specific row.
  294. * @param {Number} rowIndex The row inside the group
  295. * @param {Boolean} expanded (optional)
  296. */
  297. toggleRowIndex : function(rowIndex, expanded){
  298. if(!this.canGroup()){
  299. return;
  300. }
  301. var row = this.getRow(rowIndex);
  302. if(row){
  303. this.toggleGroup(this.findGroup(row), expanded);
  304. }
  305. },
  306. /**
  307. * Toggles the specified group if no value is passed, otherwise sets the expanded state of the group to the value passed.
  308. * @param {String} groupId The groupId assigned to the group (see getGroupId)
  309. * @param {Boolean} expanded (optional)
  310. */
  311. toggleGroup : function(group, expanded){
  312. var gel = Ext.get(group),
  313. id = Ext.util.Format.htmlEncode(gel.id);
  314. expanded = Ext.isDefined(expanded) ? expanded : gel.hasClass('x-grid-group-collapsed');
  315. if(this.state[id] !== expanded){
  316. if (this.cancelEditOnToggle !== false) {
  317. this.grid.stopEditing(true);
  318. }
  319. this.state[id] = expanded;
  320. gel[expanded ? 'removeClass' : 'addClass']('x-grid-group-collapsed');
  321. }
  322. },
  323. /**
  324. * Toggles all groups if no value is passed, otherwise sets the expanded state of all groups to the value passed.
  325. * @param {Boolean} expanded (optional)
  326. */
  327. toggleAllGroups : function(expanded){
  328. var groups = this.getGroups();
  329. for(var i = 0, len = groups.length; i < len; i++){
  330. this.toggleGroup(groups[i], expanded);
  331. }
  332. },
  333. /**
  334. * Expands all grouped rows.
  335. */
  336. expandAllGroups : function(){
  337. this.toggleAllGroups(true);
  338. },
  339. /**
  340. * Collapses all grouped rows.
  341. */
  342. collapseAllGroups : function(){
  343. this.toggleAllGroups(false);
  344. },
  345. // private
  346. getGroup : function(v, r, groupRenderer, rowIndex, colIndex, ds){
  347. var column = this.cm.config[colIndex],
  348. g = groupRenderer ? groupRenderer.call(column.scope, v, {}, r, rowIndex, colIndex, ds) : String(v);
  349. if(g === '' || g === '&#160;'){
  350. g = column.emptyGroupText || this.emptyGroupText;
  351. }
  352. return g;
  353. },
  354. // private
  355. getGroupField : function(){
  356. return this.grid.store.getGroupState();
  357. },
  358. // private
  359. afterRender : function(){
  360. if(!this.ds || !this.cm){
  361. return;
  362. }
  363. Ext.grid.GroupingView.superclass.afterRender.call(this);
  364. if(this.grid.deferRowRender){
  365. this.updateGroupWidths();
  366. }
  367. },
  368. afterRenderUI: function () {
  369. Ext.grid.GroupingView.superclass.afterRenderUI.call(this);
  370. if (this.enableGroupingMenu && this.hmenu) {
  371. this.hmenu.add('-',{
  372. itemId:'groupBy',
  373. text: this.groupByText,
  374. handler: this.onGroupByClick,
  375. scope: this,
  376. iconCls:'x-group-by-icon'
  377. });
  378. if (this.enableNoGroups) {
  379. this.hmenu.add({
  380. itemId:'showGroups',
  381. text: this.showGroupsText,
  382. checked: true,
  383. checkHandler: this.onShowGroupsClick,
  384. scope: this
  385. });
  386. }
  387. this.hmenu.on('beforeshow', this.beforeMenuShow, this);
  388. }
  389. },
  390. // private
  391. renderRows : function(){
  392. var groupField = this.getGroupField();
  393. var eg = !!groupField;
  394. // if they turned off grouping and the last grouped field is hidden
  395. if(this.hideGroupedColumn) {
  396. var colIndex = this.cm.findColumnIndex(groupField),
  397. hasLastGroupField = Ext.isDefined(this.lastGroupField);
  398. if(!eg && hasLastGroupField){
  399. this.mainBody.update('');
  400. this.cm.setHidden(this.cm.findColumnIndex(this.lastGroupField), false);
  401. delete this.lastGroupField;
  402. }else if (eg && !hasLastGroupField){
  403. this.lastGroupField = groupField;
  404. this.cm.setHidden(colIndex, true);
  405. }else if (eg && hasLastGroupField && groupField !== this.lastGroupField) {
  406. this.mainBody.update('');
  407. var oldIndex = this.cm.findColumnIndex(this.lastGroupField);
  408. this.cm.setHidden(oldIndex, false);
  409. this.lastGroupField = groupField;
  410. this.cm.setHidden(colIndex, true);
  411. }
  412. }
  413. return Ext.grid.GroupingView.superclass.renderRows.apply(
  414. this, arguments);
  415. },
  416. // private
  417. doRender : function(cs, rs, ds, startRow, colCount, stripe){
  418. if(rs.length < 1){
  419. return '';
  420. }
  421. if(!this.canGroup() || this.isUpdating){
  422. return Ext.grid.GroupingView.superclass.doRender.apply(this, arguments);
  423. }
  424. var groupField = this.getGroupField(),
  425. colIndex = this.cm.findColumnIndex(groupField),
  426. g,
  427. gstyle = 'width:' + this.getTotalWidth() + ';',
  428. cfg = this.cm.config[colIndex],
  429. groupRenderer = cfg.groupRenderer || cfg.renderer,
  430. prefix = this.showGroupName ? (cfg.groupName || cfg.header)+': ' : '',
  431. groups = [],
  432. curGroup, i, len, gid;
  433. for(i = 0, len = rs.length; i < len; i++){
  434. var rowIndex = startRow + i,
  435. r = rs[i],
  436. gvalue = r.data[groupField];
  437. g = this.getGroup(gvalue, r, groupRenderer, rowIndex, colIndex, ds);
  438. if(!curGroup || curGroup.group != g){
  439. gid = this.constructId(gvalue, groupField, colIndex);
  440. // if state is defined use it, however state is in terms of expanded
  441. // so negate it, otherwise use the default.
  442. this.state[gid] = !(Ext.isDefined(this.state[gid]) ? !this.state[gid] : this.startCollapsed);
  443. curGroup = {
  444. group: g,
  445. gvalue: gvalue,
  446. text: prefix + g,
  447. groupId: gid,
  448. startRow: rowIndex,
  449. rs: [r],
  450. cls: this.state[gid] ? '' : 'x-grid-group-collapsed',
  451. style: gstyle
  452. };
  453. groups.push(curGroup);
  454. }else{
  455. curGroup.rs.push(r);
  456. }
  457. r._groupId = gid;
  458. }
  459. var buf = [];
  460. for(i = 0, len = groups.length; i < len; i++){
  461. g = groups[i];
  462. this.doGroupStart(buf, g, cs, ds, colCount);
  463. buf[buf.length] = Ext.grid.GroupingView.superclass.doRender.call(
  464. this, cs, g.rs, ds, g.startRow, colCount, stripe);
  465. this.doGroupEnd(buf, g, cs, ds, colCount);
  466. }
  467. return buf.join('');
  468. },
  469. /**
  470. * Dynamically tries to determine the groupId of a specific value
  471. * @param {String} value
  472. * @return {String} The group id
  473. */
  474. getGroupId : function(value){
  475. var field = this.getGroupField();
  476. return this.constructId(value, field, this.cm.findColumnIndex(field));
  477. },
  478. // private
  479. constructId : function(value, field, idx){
  480. var cfg = this.cm.config[idx],
  481. groupRenderer = cfg.groupRenderer || cfg.renderer,
  482. val = (this.groupMode == 'value') ? value : this.getGroup(value, {data:{}}, groupRenderer, 0, idx, this.ds);
  483. return this.getPrefix(field) + Ext.util.Format.htmlEncode(val);
  484. },
  485. // private
  486. canGroup : function(){
  487. return this.enableGrouping && !!this.getGroupField();
  488. },
  489. // private
  490. getPrefix: function(field){
  491. return this.grid.getGridEl().id + '-gp-' + field + '-';
  492. },
  493. // private
  494. doGroupStart : function(buf, g, cs, ds, colCount){
  495. buf[buf.length] = this.startGroup.apply(g);
  496. },
  497. // private
  498. doGroupEnd : function(buf, g, cs, ds, colCount){
  499. buf[buf.length] = this.endGroup;
  500. },
  501. // private
  502. getRows : function(){
  503. if(!this.canGroup()){
  504. return Ext.grid.GroupingView.superclass.getRows.call(this);
  505. }
  506. var r = [],
  507. gs = this.getGroups(),
  508. g,
  509. i = 0,
  510. len = gs.length,
  511. j,
  512. jlen;
  513. for(; i < len; ++i){
  514. g = gs[i].childNodes[1];
  515. if(g){
  516. g = g.childNodes;
  517. for(j = 0, jlen = g.length; j < jlen; ++j){
  518. r[r.length] = g[j];
  519. }
  520. }
  521. }
  522. return r;
  523. },
  524. // private
  525. updateGroupWidths : function(){
  526. if(!this.canGroup() || !this.hasRows()){
  527. return;
  528. }
  529. var tw = Math.max(this.cm.getTotalWidth(), this.el.dom.offsetWidth-this.getScrollOffset()) +'px';
  530. var gs = this.getGroups();
  531. for(var i = 0, len = gs.length; i < len; i++){
  532. gs[i].firstChild.style.width = tw;
  533. }
  534. },
  535. // private
  536. onColumnWidthUpdated : function(col, w, tw){
  537. Ext.grid.GroupingView.superclass.onColumnWidthUpdated.call(this, col, w, tw);
  538. this.updateGroupWidths();
  539. },
  540. // private
  541. onAllColumnWidthsUpdated : function(ws, tw){
  542. Ext.grid.GroupingView.superclass.onAllColumnWidthsUpdated.call(this, ws, tw);
  543. this.updateGroupWidths();
  544. },
  545. // private
  546. onColumnHiddenUpdated : function(col, hidden, tw){
  547. Ext.grid.GroupingView.superclass.onColumnHiddenUpdated.call(this, col, hidden, tw);
  548. this.updateGroupWidths();
  549. },
  550. // private
  551. onLayout : function(){
  552. this.updateGroupWidths();
  553. },
  554. // private
  555. onBeforeRowSelect : function(sm, rowIndex){
  556. this.toggleRowIndex(rowIndex, true);
  557. }
  558. });
  559. // private
  560. Ext.grid.GroupingView.GROUP_ID = 1000;