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.

466 lines
18 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-PivotGridView'>/**
  19. </span> * @class Ext.grid.PivotGridView
  20. * @extends Ext.grid.GridView
  21. * Specialised GridView for rendering Pivot Grid components. Config can be passed to the PivotGridView via the PivotGrid constructor's
  22. * viewConfig option:
  23. &lt;pre&gt;&lt;code&gt;
  24. new Ext.grid.PivotGrid({
  25. viewConfig: {
  26. title: 'My Pivot Grid',
  27. getCellCls: function(value) {
  28. return value &gt; 10 'red' : 'green';
  29. }
  30. }
  31. });
  32. &lt;/code&gt;&lt;/pre&gt;
  33. * &lt;p&gt;Currently {@link #title} and {@link #getCellCls} are the only configuration options accepted by PivotGridView. All other
  34. * interaction is performed via the {@link Ext.grid.PivotGrid PivotGrid} class.&lt;/p&gt;
  35. */
  36. Ext.grid.PivotGridView = Ext.extend(Ext.grid.GridView, {
  37. <span id='Ext-grid-PivotGridView-property-colHeaderCellCls'> /**
  38. </span> * The CSS class added to all group header cells. Defaults to 'grid-hd-group-cell'
  39. * @property colHeaderCellCls
  40. * @type String
  41. */
  42. colHeaderCellCls: 'grid-hd-group-cell',
  43. <span id='Ext-grid-PivotGridView-cfg-title'> /**
  44. </span> * @cfg {String} title Optional title to be placed in the top left corner of the PivotGrid. Defaults to an empty string.
  45. */
  46. title: '',
  47. <span id='Ext-grid-PivotGridView-cfg-getCellCls'> /**
  48. </span> * @cfg {Function} getCellCls Optional function which should return a CSS class name for each cell value. This is useful when
  49. * color coding cells based on their value. Defaults to undefined.
  50. */
  51. <span id='Ext-grid-PivotGridView-method-getColumnHeaders'> /**
  52. </span> * Returns the headers to be rendered at the top of the grid. Should be a 2-dimensional array, where each item specifies the number
  53. * of columns it groups (column in this case refers to normal grid columns). In the example below we have 5 city groups, which are
  54. * each part of a continent supergroup. The colspan for each city group refers to the number of normal grid columns that group spans,
  55. * so in this case the grid would be expected to have a total of 12 columns:
  56. &lt;pre&gt;&lt;code&gt;
  57. [
  58. {
  59. items: [
  60. {header: 'England', colspan: 5},
  61. {header: 'USA', colspan: 3}
  62. ]
  63. },
  64. {
  65. items: [
  66. {header: 'London', colspan: 2},
  67. {header: 'Cambridge', colspan: 3},
  68. {header: 'Palo Alto', colspan: 3}
  69. ]
  70. }
  71. ]
  72. &lt;/code&gt;&lt;/pre&gt;
  73. * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -&gt; Country -&gt;
  74. * State -&gt; City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
  75. * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
  76. * be the sum of all child nodes beneath this node.
  77. */
  78. getColumnHeaders: function() {
  79. return this.grid.topAxis.buildHeaders();;
  80. },
  81. <span id='Ext-grid-PivotGridView-method-getRowHeaders'> /**
  82. </span> * Returns the headers to be rendered on the left of the grid. Should be a 2-dimensional array, where each item specifies the number
  83. * of rows it groups. In the example below we have 5 city groups, which are each part of a continent supergroup. The rowspan for each
  84. * city group refers to the number of normal grid columns that group spans, so in this case the grid would be expected to have a
  85. * total of 12 rows:
  86. &lt;pre&gt;&lt;code&gt;
  87. [
  88. {
  89. width: 90,
  90. items: [
  91. {header: 'England', rowspan: 5},
  92. {header: 'USA', rowspan: 3}
  93. ]
  94. },
  95. {
  96. width: 50,
  97. items: [
  98. {header: 'London', rowspan: 2},
  99. {header: 'Cambridge', rowspan: 3},
  100. {header: 'Palo Alto', rowspan: 3}
  101. ]
  102. }
  103. ]
  104. &lt;/code&gt;&lt;/pre&gt;
  105. * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -&gt; Country -&gt;
  106. * State -&gt; City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
  107. * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
  108. * be the sum of all child nodes beneath this node.
  109. * Each group may specify the width it should be rendered with.
  110. * @return {Array} The row groups
  111. */
  112. getRowHeaders: function() {
  113. return this.grid.leftAxis.buildHeaders();
  114. },
  115. <span id='Ext-grid-PivotGridView-method-renderRows'> /**
  116. </span> * @private
  117. * Renders rows between start and end indexes
  118. * @param {Number} startRow Index of the first row to render
  119. * @param {Number} endRow Index of the last row to render
  120. */
  121. renderRows : function(startRow, endRow) {
  122. var grid = this.grid,
  123. rows = grid.extractData(),
  124. rowCount = rows.length,
  125. templates = this.templates,
  126. renderer = grid.renderer,
  127. hasRenderer = typeof renderer == 'function',
  128. getCellCls = this.getCellCls,
  129. hasGetCellCls = typeof getCellCls == 'function',
  130. cellTemplate = templates.cell,
  131. rowTemplate = templates.row,
  132. rowBuffer = [],
  133. meta = {},
  134. tstyle = 'width:' + this.getGridInnerWidth() + 'px;',
  135. colBuffer, colCount, column, i, row;
  136. startRow = startRow || 0;
  137. endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
  138. for (i = 0; i &lt; rowCount; i++) {
  139. row = rows[i];
  140. colCount = row.length;
  141. colBuffer = [];
  142. //build up each column's HTML
  143. for (var j = 0; j &lt; colCount; j++) {
  144. meta.id = i + '-' + j;
  145. meta.css = j === 0 ? 'x-grid3-cell-first ' : (j == (colCount - 1) ? 'x-grid3-cell-last ' : '');
  146. meta.attr = meta.cellAttr = '';
  147. meta.value = row[j];
  148. if (Ext.isEmpty(meta.value)) {
  149. meta.value = '&amp;#160;';
  150. }
  151. if (hasRenderer) {
  152. meta.value = renderer(meta.value);
  153. }
  154. if (hasGetCellCls) {
  155. meta.css += getCellCls(meta.value) + ' ';
  156. }
  157. colBuffer[colBuffer.length] = cellTemplate.apply(meta);
  158. }
  159. rowBuffer[rowBuffer.length] = rowTemplate.apply({
  160. tstyle: tstyle,
  161. cols : colCount,
  162. cells : colBuffer.join(&quot;&quot;),
  163. alt : ''
  164. });
  165. }
  166. return rowBuffer.join(&quot;&quot;);
  167. },
  168. <span id='Ext-grid-PivotGridView-property-Ext.Template'> /**
  169. </span> * The master template to use when rendering the GridView. Has a default template
  170. * @property Ext.Template
  171. * @type masterTpl
  172. */
  173. masterTpl: new Ext.Template(
  174. '&lt;div class=&quot;x-grid3 x-pivotgrid&quot; hidefocus=&quot;true&quot;&gt;',
  175. '&lt;div class=&quot;x-grid3-viewport&quot;&gt;',
  176. '&lt;div class=&quot;x-grid3-header&quot;&gt;',
  177. '&lt;div class=&quot;x-grid3-header-title&quot;&gt;&lt;span&gt;{title}&lt;/span&gt;&lt;/div&gt;',
  178. '&lt;div class=&quot;x-grid3-header-inner&quot;&gt;',
  179. '&lt;div class=&quot;x-grid3-header-offset&quot; style=&quot;{ostyle}&quot;&gt;&lt;/div&gt;',
  180. '&lt;/div&gt;',
  181. '&lt;div class=&quot;x-clear&quot;&gt;&lt;/div&gt;',
  182. '&lt;/div&gt;',
  183. '&lt;div class=&quot;x-grid3-scroller&quot;&gt;',
  184. '&lt;div class=&quot;x-grid3-row-headers&quot;&gt;&lt;/div&gt;',
  185. '&lt;div class=&quot;x-grid3-body&quot; style=&quot;{bstyle}&quot;&gt;{body}&lt;/div&gt;',
  186. '&lt;a href=&quot;#&quot; class=&quot;x-grid3-focus&quot; tabIndex=&quot;-1&quot;&gt;&lt;/a&gt;',
  187. '&lt;/div&gt;',
  188. '&lt;/div&gt;',
  189. '&lt;div class=&quot;x-grid3-resize-marker&quot;&gt;&amp;#160;&lt;/div&gt;',
  190. '&lt;div class=&quot;x-grid3-resize-proxy&quot;&gt;&amp;#160;&lt;/div&gt;',
  191. '&lt;/div&gt;'
  192. ),
  193. <span id='Ext-grid-PivotGridView-method-initTemplates'> /**
  194. </span> * @private
  195. * Adds a gcell template to the internal templates object. This is used to render the headers in a multi-level column header.
  196. */
  197. initTemplates: function() {
  198. Ext.grid.PivotGridView.superclass.initTemplates.apply(this, arguments);
  199. var templates = this.templates || {};
  200. if (!templates.gcell) {
  201. templates.gcell = new Ext.XTemplate(
  202. '&lt;td class=&quot;x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} ' + this.colHeaderCellCls + '&quot; style=&quot;{style}&quot;&gt;',
  203. '&lt;div {tooltip} class=&quot;x-grid3-hd-inner x-grid3-hd-{id} x-unselectable&quot; unselectable=&quot;on&quot; style=&quot;{istyle}&quot;&gt;',
  204. this.grid.enableHdMenu ? '&lt;a class=&quot;x-grid3-hd-btn&quot; href=&quot;#&quot;&gt;&lt;/a&gt;' : '', '{value}',
  205. '&lt;/div&gt;',
  206. '&lt;/td&gt;'
  207. );
  208. }
  209. this.templates = templates;
  210. this.hrowRe = new RegExp(&quot;ux-grid-hd-group-row-(\\d+)&quot;, &quot;&quot;);
  211. },
  212. <span id='Ext-grid-PivotGridView-method-initElements'> /**
  213. </span> * @private
  214. * Sets up the reference to the row headers element
  215. */
  216. initElements: function() {
  217. Ext.grid.PivotGridView.superclass.initElements.apply(this, arguments);
  218. <span id='Ext-grid-PivotGridView-property-rowHeadersEl'> /**
  219. </span> * @property rowHeadersEl
  220. * @type Ext.Element
  221. * The element containing all row headers
  222. */
  223. this.rowHeadersEl = new Ext.Element(this.scroller.child('div.x-grid3-row-headers'));
  224. <span id='Ext-grid-PivotGridView-property-headerTitleEl'> /**
  225. </span> * @property headerTitleEl
  226. * @type Ext.Element
  227. * The element that contains the optional title (top left section of the pivot grid)
  228. */
  229. this.headerTitleEl = new Ext.Element(this.mainHd.child('div.x-grid3-header-title'));
  230. },
  231. <span id='Ext-grid-PivotGridView-method-getGridInnerWidth'> /**
  232. </span> * @private
  233. * Takes row headers into account when calculating total available width
  234. */
  235. getGridInnerWidth: function() {
  236. var previousWidth = Ext.grid.PivotGridView.superclass.getGridInnerWidth.apply(this, arguments);
  237. return previousWidth - this.getTotalRowHeaderWidth();
  238. },
  239. <span id='Ext-grid-PivotGridView-method-getTotalRowHeaderWidth'> /**
  240. </span> * Returns the total width of all row headers as specified by {@link #getRowHeaders}
  241. * @return {Number} The total width
  242. */
  243. getTotalRowHeaderWidth: function() {
  244. var headers = this.getRowHeaders(),
  245. length = headers.length,
  246. total = 0,
  247. i;
  248. for (i = 0; i&lt; length; i++) {
  249. total += headers[i].width;
  250. }
  251. return total;
  252. },
  253. <span id='Ext-grid-PivotGridView-method-getTotalColumnHeaderHeight'> /**
  254. </span> * @private
  255. * Returns the total height of all column headers
  256. * @return {Number} The total height
  257. */
  258. getTotalColumnHeaderHeight: function() {
  259. return this.getColumnHeaders().length * 21;
  260. },
  261. <span id='Ext-grid-PivotGridView-method-getCellIndex'> /**
  262. </span> * Inherit docs
  263. * @private
  264. * @param {HTMLElement} el
  265. */
  266. getCellIndex : function(el) {
  267. if (el) {
  268. var match = el.className.match(this.colRe),
  269. data;
  270. if (match &amp;&amp; (data = match[1])) {
  271. return parseInt(data.split('-')[1], 10);
  272. }
  273. }
  274. return false;
  275. },
  276. <span id='Ext-grid-PivotGridView-method-renderUI'> /**
  277. </span> * @private
  278. * Slight specialisation of the GridView renderUI - just adds the row headers
  279. */
  280. renderUI : function() {
  281. var templates = this.templates,
  282. innerWidth = this.getGridInnerWidth();
  283. return templates.master.apply({
  284. body : templates.body.apply({rows:'&amp;#160;'}),
  285. ostyle: 'width:' + innerWidth + 'px',
  286. bstyle: 'width:' + innerWidth + 'px'
  287. });
  288. },
  289. <span id='Ext-grid-PivotGridView-method-onLayout'> /**
  290. </span> * @private
  291. * Make sure that the headers and rows are all sized correctly during layout
  292. */
  293. onLayout: function(width, height) {
  294. Ext.grid.PivotGridView.superclass.onLayout.apply(this, arguments);
  295. var width = this.getGridInnerWidth();
  296. this.resizeColumnHeaders(width);
  297. this.resizeAllRows(width);
  298. },
  299. <span id='Ext-grid-PivotGridView-method-refresh'> /**
  300. </span> * Refreshs the grid UI
  301. * @param {Boolean} headersToo (optional) True to also refresh the headers
  302. */
  303. refresh : function(headersToo) {
  304. this.fireEvent('beforerefresh', this);
  305. this.grid.stopEditing(true);
  306. var result = this.renderBody();
  307. this.mainBody.update(result).setWidth(this.getGridInnerWidth());
  308. if (headersToo === true) {
  309. this.updateHeaders();
  310. this.updateHeaderSortState();
  311. }
  312. this.processRows(0, true);
  313. this.layout();
  314. this.applyEmptyText();
  315. this.fireEvent('refresh', this);
  316. },
  317. <span id='Ext-grid-PivotGridView-method-renderHeaders'> /**
  318. </span> * @private
  319. * Bypasses GridView's renderHeaders as they are taken care of separately by the PivotAxis instances
  320. */
  321. renderHeaders: Ext.emptyFn,
  322. <span id='Ext-grid-PivotGridView-method-fitColumns'> /**
  323. </span> * @private
  324. * Taken care of by PivotAxis
  325. */
  326. fitColumns: Ext.emptyFn,
  327. <span id='Ext-grid-PivotGridView-method-resizeColumnHeaders'> /**
  328. </span> * @private
  329. * Called on layout, ensures that the width of each column header is correct. Omitting this can lead to faulty
  330. * layouts when nested in a container.
  331. * @param {Number} width The new width
  332. */
  333. resizeColumnHeaders: function(width) {
  334. var topAxis = this.grid.topAxis;
  335. if (topAxis.rendered) {
  336. topAxis.el.setWidth(width);
  337. }
  338. },
  339. <span id='Ext-grid-PivotGridView-method-resizeRowHeaders'> /**
  340. </span> * @private
  341. * Sets the row header div to the correct width. Should be called after rendering and reconfiguration of headers
  342. */
  343. resizeRowHeaders: function() {
  344. var rowHeaderWidth = this.getTotalRowHeaderWidth(),
  345. marginStyle = String.format(&quot;margin-left: {0}px;&quot;, rowHeaderWidth);
  346. this.rowHeadersEl.setWidth(rowHeaderWidth);
  347. this.mainBody.applyStyles(marginStyle);
  348. Ext.fly(this.innerHd).applyStyles(marginStyle);
  349. this.headerTitleEl.setWidth(rowHeaderWidth);
  350. this.headerTitleEl.setHeight(this.getTotalColumnHeaderHeight());
  351. },
  352. <span id='Ext-grid-PivotGridView-method-resizeAllRows'> /**
  353. </span> * @private
  354. * Resizes all rendered rows to the given width. Usually called by onLayout
  355. * @param {Number} width The new width
  356. */
  357. resizeAllRows: function(width) {
  358. var rows = this.getRows(),
  359. length = rows.length,
  360. i;
  361. for (i = 0; i &lt; length; i++) {
  362. Ext.fly(rows[i]).setWidth(width);
  363. Ext.fly(rows[i]).child('table').setWidth(width);
  364. }
  365. },
  366. <span id='Ext-grid-PivotGridView-method-updateHeaders'> /**
  367. </span> * @private
  368. * Updates the Row Headers, deferring the updating of Column Headers to GridView
  369. */
  370. updateHeaders: function() {
  371. this.renderGroupRowHeaders();
  372. this.renderGroupColumnHeaders();
  373. },
  374. <span id='Ext-grid-PivotGridView-method-renderGroupRowHeaders'> /**
  375. </span> * @private
  376. * Renders all row header groups at all levels based on the structure fetched from {@link #getGroupRowHeaders}
  377. */
  378. renderGroupRowHeaders: function() {
  379. var leftAxis = this.grid.leftAxis;
  380. this.resizeRowHeaders();
  381. leftAxis.rendered = false;
  382. leftAxis.render(this.rowHeadersEl);
  383. this.setTitle(this.title);
  384. },
  385. <span id='Ext-grid-PivotGridView-method-setTitle'> /**
  386. </span> * Sets the title text in the top left segment of the PivotGridView
  387. * @param {String} title The title
  388. */
  389. setTitle: function(title) {
  390. this.headerTitleEl.child('span').dom.innerHTML = title;
  391. },
  392. <span id='Ext-grid-PivotGridView-method-renderGroupColumnHeaders'> /**
  393. </span> * @private
  394. * Renders all column header groups at all levels based on the structure fetched from {@link #getColumnHeaders}
  395. */
  396. renderGroupColumnHeaders: function() {
  397. var topAxis = this.grid.topAxis;
  398. topAxis.rendered = false;
  399. topAxis.render(this.innerHd.firstChild);
  400. },
  401. <span id='Ext-grid-PivotGridView-method-isMenuDisabled'> /**
  402. </span> * @private
  403. * Overridden to test whether the user is hovering over a group cell, in which case we don't show the menu
  404. */
  405. isMenuDisabled: function(cellIndex, el) {
  406. return true;
  407. }
  408. });</pre>
  409. </body>
  410. </html>