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
27 KiB

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