Web UI for ARGUS server
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.

618 lines
24 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  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>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.grid.GroupingView"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-groupByText"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-showGroupsText"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-hideGroupedColumn"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-showGroupName"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-startCollapsed"></div>/**
  95. * @cfg {Boolean} startCollapsed <tt>true</tt> to start all groups collapsed (defaults to <tt>false</tt>)
  96. */
  97. startCollapsed : false,
  98. <div id="cfg-Ext.grid.GroupingView-enableGrouping"></div>/**
  99. * @cfg {Boolean} enableGrouping <tt>false</tt> to disable grouping functionality (defaults to <tt>true</tt>)
  100. */
  101. enableGrouping : true,
  102. <div id="cfg-Ext.grid.GroupingView-enableGroupingMenu"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-enableNoGroups"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-emptyGroupText"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-ignoreAdd"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-groupTextTpl"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-groupMode"></div>/**
  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. <div id="cfg-Ext.grid.GroupingView-groupRenderer"></div>/**
  153. * @cfg {Function} groupRenderer This property must be configured in the {@link Ext.grid.Column} for
  154. * each column.
  155. */
  156. <div id="cfg-Ext.grid.GroupingView-cancelEditOnToggle"></div>/**
  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. <div id="method-Ext.grid.GroupingView-toggleRowIndex"></div>/**
  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. <div id="method-Ext.grid.GroupingView-toggleGroup"></div>/**
  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. expanded = Ext.isDefined(expanded) ? expanded : gel.hasClass('x-grid-group-collapsed');
  314. if(this.state[gel.id] !== expanded){
  315. if (this.cancelEditOnToggle !== false) {
  316. this.grid.stopEditing(true);
  317. }
  318. this.state[gel.id] = expanded;
  319. gel[expanded ? 'removeClass' : 'addClass']('x-grid-group-collapsed');
  320. }
  321. },
  322. <div id="method-Ext.grid.GroupingView-toggleAllGroups"></div>/**
  323. * Toggles all groups if no value is passed, otherwise sets the expanded state of all groups to the value passed.
  324. * @param {Boolean} expanded (optional)
  325. */
  326. toggleAllGroups : function(expanded){
  327. var groups = this.getGroups();
  328. for(var i = 0, len = groups.length; i < len; i++){
  329. this.toggleGroup(groups[i], expanded);
  330. }
  331. },
  332. <div id="method-Ext.grid.GroupingView-expandAllGroups"></div>/**
  333. * Expands all grouped rows.
  334. */
  335. expandAllGroups : function(){
  336. this.toggleAllGroups(true);
  337. },
  338. <div id="method-Ext.grid.GroupingView-collapseAllGroups"></div>/**
  339. * Collapses all grouped rows.
  340. */
  341. collapseAllGroups : function(){
  342. this.toggleAllGroups(false);
  343. },
  344. // private
  345. getGroup : function(v, r, groupRenderer, rowIndex, colIndex, ds){
  346. var column = this.cm.config[colIndex],
  347. g = groupRenderer ? groupRenderer.call(column.scope, v, {}, r, rowIndex, colIndex, ds) : String(v);
  348. if(g === '' || g === '&#160;'){
  349. g = column.emptyGroupText || this.emptyGroupText;
  350. }
  351. return g;
  352. },
  353. // private
  354. getGroupField : function(){
  355. return this.grid.store.getGroupState();
  356. },
  357. // private
  358. afterRender : function(){
  359. if(!this.ds || !this.cm){
  360. return;
  361. }
  362. Ext.grid.GroupingView.superclass.afterRender.call(this);
  363. if(this.grid.deferRowRender){
  364. this.updateGroupWidths();
  365. }
  366. },
  367. afterRenderUI: function () {
  368. Ext.grid.GroupingView.superclass.afterRenderUI.call(this);
  369. if (this.enableGroupingMenu && this.hmenu) {
  370. this.hmenu.add('-',{
  371. itemId:'groupBy',
  372. text: this.groupByText,
  373. handler: this.onGroupByClick,
  374. scope: this,
  375. iconCls:'x-group-by-icon'
  376. });
  377. if (this.enableNoGroups) {
  378. this.hmenu.add({
  379. itemId:'showGroups',
  380. text: this.showGroupsText,
  381. checked: true,
  382. checkHandler: this.onShowGroupsClick,
  383. scope: this
  384. });
  385. }
  386. this.hmenu.on('beforeshow', this.beforeMenuShow, this);
  387. }
  388. },
  389. // private
  390. renderRows : function(){
  391. var groupField = this.getGroupField();
  392. var eg = !!groupField;
  393. // if they turned off grouping and the last grouped field is hidden
  394. if(this.hideGroupedColumn) {
  395. var colIndex = this.cm.findColumnIndex(groupField),
  396. hasLastGroupField = Ext.isDefined(this.lastGroupField);
  397. if(!eg && hasLastGroupField){
  398. this.mainBody.update('');
  399. this.cm.setHidden(this.cm.findColumnIndex(this.lastGroupField), false);
  400. delete this.lastGroupField;
  401. }else if (eg && !hasLastGroupField){
  402. this.lastGroupField = groupField;
  403. this.cm.setHidden(colIndex, true);
  404. }else if (eg && hasLastGroupField && groupField !== this.lastGroupField) {
  405. this.mainBody.update('');
  406. var oldIndex = this.cm.findColumnIndex(this.lastGroupField);
  407. this.cm.setHidden(oldIndex, false);
  408. this.lastGroupField = groupField;
  409. this.cm.setHidden(colIndex, true);
  410. }
  411. }
  412. return Ext.grid.GroupingView.superclass.renderRows.apply(
  413. this, arguments);
  414. },
  415. // private
  416. doRender : function(cs, rs, ds, startRow, colCount, stripe){
  417. if(rs.length < 1){
  418. return '';
  419. }
  420. if(!this.canGroup() || this.isUpdating){
  421. return Ext.grid.GroupingView.superclass.doRender.apply(this, arguments);
  422. }
  423. var groupField = this.getGroupField(),
  424. colIndex = this.cm.findColumnIndex(groupField),
  425. g,
  426. gstyle = 'width:' + this.getTotalWidth() + ';',
  427. cfg = this.cm.config[colIndex],
  428. groupRenderer = cfg.groupRenderer || cfg.renderer,
  429. prefix = this.showGroupName ? (cfg.groupName || cfg.header)+': ' : '',
  430. groups = [],
  431. curGroup, i, len, gid;
  432. for(i = 0, len = rs.length; i < len; i++){
  433. var rowIndex = startRow + i,
  434. r = rs[i],
  435. gvalue = r.data[groupField];
  436. g = this.getGroup(gvalue, r, groupRenderer, rowIndex, colIndex, ds);
  437. if(!curGroup || curGroup.group != g){
  438. gid = this.constructId(gvalue, groupField, colIndex);
  439. // if state is defined use it, however state is in terms of expanded
  440. // so negate it, otherwise use the default.
  441. this.state[gid] = !(Ext.isDefined(this.state[gid]) ? !this.state[gid] : this.startCollapsed);
  442. curGroup = {
  443. group: g,
  444. gvalue: gvalue,
  445. text: prefix + g,
  446. groupId: gid,
  447. startRow: rowIndex,
  448. rs: [r],
  449. cls: this.state[gid] ? '' : 'x-grid-group-collapsed',
  450. style: gstyle
  451. };
  452. groups.push(curGroup);
  453. }else{
  454. curGroup.rs.push(r);
  455. }
  456. r._groupId = gid;
  457. }
  458. var buf = [];
  459. for(i = 0, len = groups.length; i < len; i++){
  460. g = groups[i];
  461. this.doGroupStart(buf, g, cs, ds, colCount);
  462. buf[buf.length] = Ext.grid.GroupingView.superclass.doRender.call(
  463. this, cs, g.rs, ds, g.startRow, colCount, stripe);
  464. this.doGroupEnd(buf, g, cs, ds, colCount);
  465. }
  466. return buf.join('');
  467. },
  468. <div id="method-Ext.grid.GroupingView-getGroupId"></div>/**
  469. * Dynamically tries to determine the groupId of a specific value
  470. * @param {String} value
  471. * @return {String} The group id
  472. */
  473. getGroupId : function(value){
  474. var field = this.getGroupField();
  475. return this.constructId(value, field, this.cm.findColumnIndex(field));
  476. },
  477. // private
  478. constructId : function(value, field, idx){
  479. var cfg = this.cm.config[idx],
  480. groupRenderer = cfg.groupRenderer || cfg.renderer,
  481. val = (this.groupMode == 'value') ? value : this.getGroup(value, {data:{}}, groupRenderer, 0, idx, this.ds);
  482. return this.getPrefix(field) + Ext.util.Format.htmlEncode(val);
  483. },
  484. // private
  485. canGroup : function(){
  486. return this.enableGrouping && !!this.getGroupField();
  487. },
  488. // private
  489. getPrefix: function(field){
  490. return this.grid.getGridEl().id + '-gp-' + field + '-';
  491. },
  492. // private
  493. doGroupStart : function(buf, g, cs, ds, colCount){
  494. buf[buf.length] = this.startGroup.apply(g);
  495. },
  496. // private
  497. doGroupEnd : function(buf, g, cs, ds, colCount){
  498. buf[buf.length] = this.endGroup;
  499. },
  500. // private
  501. getRows : function(){
  502. if(!this.canGroup()){
  503. return Ext.grid.GroupingView.superclass.getRows.call(this);
  504. }
  505. var r = [],
  506. gs = this.getGroups(),
  507. g,
  508. i = 0,
  509. len = gs.length,
  510. j,
  511. jlen;
  512. for(; i < len; ++i){
  513. g = gs[i].childNodes[1];
  514. if(g){
  515. g = g.childNodes;
  516. for(j = 0, jlen = g.length; j < jlen; ++j){
  517. r[r.length] = g[j];
  518. }
  519. }
  520. }
  521. return r;
  522. },
  523. // private
  524. updateGroupWidths : function(){
  525. if(!this.canGroup() || !this.hasRows()){
  526. return;
  527. }
  528. var tw = Math.max(this.cm.getTotalWidth(), this.el.dom.offsetWidth-this.getScrollOffset()) +'px';
  529. var gs = this.getGroups();
  530. for(var i = 0, len = gs.length; i < len; i++){
  531. gs[i].firstChild.style.width = tw;
  532. }
  533. },
  534. // private
  535. onColumnWidthUpdated : function(col, w, tw){
  536. Ext.grid.GroupingView.superclass.onColumnWidthUpdated.call(this, col, w, tw);
  537. this.updateGroupWidths();
  538. },
  539. // private
  540. onAllColumnWidthsUpdated : function(ws, tw){
  541. Ext.grid.GroupingView.superclass.onAllColumnWidthsUpdated.call(this, ws, tw);
  542. this.updateGroupWidths();
  543. },
  544. // private
  545. onColumnHiddenUpdated : function(col, hidden, tw){
  546. Ext.grid.GroupingView.superclass.onColumnHiddenUpdated.call(this, col, hidden, tw);
  547. this.updateGroupWidths();
  548. },
  549. // private
  550. onLayout : function(){
  551. this.updateGroupWidths();
  552. },
  553. // private
  554. onBeforeRowSelect : function(sm, rowIndex){
  555. this.toggleRowIndex(rowIndex, true);
  556. }
  557. });
  558. // private
  559. Ext.grid.GroupingView.GROUP_ID = 1000;</pre>
  560. </body>
  561. </html>