AbstractSummary.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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-feature-AbstractSummary'>/**
  19. </span> * A small abstract class that contains the shared behaviour for any summary
  20. * calculations to be used in the grid.
  21. */
  22. Ext.define('Ext.grid.feature.AbstractSummary', {
  23. /* Begin Definitions */
  24. extend: 'Ext.grid.feature.Feature',
  25. alias: 'feature.abstractsummary',
  26. /* End Definitions */
  27. <span id='Ext-grid-feature-AbstractSummary-cfg-showSummaryRow'> /**
  28. </span> * @cfg
  29. * True to show the summary row.
  30. */
  31. showSummaryRow: true,
  32. // @private
  33. nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
  34. // Listen for store updates. Eg, from an Editor.
  35. init: function() {
  36. var me = this;
  37. // Summary rows must be kept in column order, so view must be refreshed on column move
  38. me.grid.optimizedColumnMove = false;
  39. me.view.mon(me.view.store, {
  40. update: me.onStoreUpdate,
  41. scope: me
  42. });
  43. },
  44. // Refresh the whole view on edit so that the Summary gets updated
  45. onStoreUpdate: function() {
  46. var v = this.view;
  47. if (this.showSummaryRow) {
  48. v.saveScrollState();
  49. v.refresh();
  50. v.restoreScrollState();
  51. }
  52. },
  53. <span id='Ext-grid-feature-AbstractSummary-method-toggleSummaryRow'> /**
  54. </span> * Toggle whether or not to show the summary row.
  55. * @param {Boolean} visible True to show the summary row
  56. */
  57. toggleSummaryRow: function(visible){
  58. this.showSummaryRow = !!visible;
  59. },
  60. <span id='Ext-grid-feature-AbstractSummary-method-getSummaryFragments'> /**
  61. </span> * Gets any fragments to be used in the tpl
  62. * @private
  63. * @return {Object} The fragments
  64. */
  65. getSummaryFragments: function(){
  66. var fragments = {};
  67. if (this.showSummaryRow) {
  68. Ext.apply(fragments, {
  69. printSummaryRow: Ext.bind(this.printSummaryRow, this)
  70. });
  71. }
  72. return fragments;
  73. },
  74. <span id='Ext-grid-feature-AbstractSummary-method-printSummaryRow'> /**
  75. </span> * Prints a summary row
  76. * @private
  77. * @param {Object} index The index in the template
  78. * @return {String} The value of the summary row
  79. */
  80. printSummaryRow: function(index){
  81. var inner = this.view.getTableChunker().metaRowTpl.join(''),
  82. prefix = Ext.baseCSSPrefix;
  83. inner = inner.replace(prefix + 'grid-row', prefix + 'grid-row-summary');
  84. inner = inner.replace('{{id}}', '{gridSummaryValue}');
  85. inner = inner.replace(this.nestedIdRe, '{id$1}');
  86. inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
  87. inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
  88. inner = new Ext.XTemplate(inner, {
  89. firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
  90. });
  91. return inner.applyTemplate({
  92. columns: this.getPrintData(index)
  93. });
  94. },
  95. <span id='Ext-grid-feature-AbstractSummary-method-getColumnValue'> /**
  96. </span> * Gets the value for the column from the attached data.
  97. * @param {Ext.grid.column.Column} column The header
  98. * @param {Object} data The current data
  99. * @return {String} The value to be rendered
  100. */
  101. getColumnValue: function(column, summaryData){
  102. var comp = Ext.getCmp(column.id),
  103. value = summaryData[column.id],
  104. renderer = comp.summaryRenderer;
  105. if (!value &amp;&amp; value !== 0) {
  106. value = '\u00a0';
  107. }
  108. if (renderer) {
  109. value = renderer.call(
  110. comp.scope || this,
  111. value,
  112. summaryData,
  113. column.dataIndex
  114. );
  115. }
  116. return value;
  117. },
  118. <span id='Ext-grid-feature-AbstractSummary-method-getSummary'> /**
  119. </span> * Get the summary data for a field.
  120. * @private
  121. * @param {Ext.data.Store} store The store to get the data from
  122. * @param {String/Function} type The type of aggregation. If a function is specified it will
  123. * be passed to the stores aggregate function.
  124. * @param {String} field The field to aggregate on
  125. * @param {Boolean} group True to aggregate in grouped mode
  126. * @return {Number/String/Object} See the return type for the store functions.
  127. */
  128. getSummary: function(store, type, field, group){
  129. if (type) {
  130. if (Ext.isFunction(type)) {
  131. return store.aggregate(type, null, group);
  132. }
  133. switch (type) {
  134. case 'count':
  135. return store.count(group);
  136. case 'min':
  137. return store.min(field, group);
  138. case 'max':
  139. return store.max(field, group);
  140. case 'sum':
  141. return store.sum(field, group);
  142. case 'average':
  143. return store.average(field, group);
  144. default:
  145. return group ? {} : '';
  146. }
  147. }
  148. }
  149. });
  150. </pre>
  151. </body>
  152. </html>