4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
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 * @class Ext.grid.feature.AbstractSummary
22 * @extends Ext.grid.feature.Feature
25 Ext.define('Ext.grid.feature.AbstractSummary', {
27 /* Begin Definitions */
29 extend: 'Ext.grid.feature.Feature',
31 alias: 'feature.abstractsummary',
35 <span id='Ext-grid-feature-AbstractSummary-cfg-showSummaryRow'> /**
36 </span> * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to <tt>true</tt>.
41 nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
43 <span id='Ext-grid-feature-AbstractSummary-method-toggleSummaryRow'> /**
44 </span> * Toggle whether or not to show the summary row.
45 * @param {Boolan} visible True to show the summary row
47 toggleSummaryRow: function(visible){
48 this.showSummaryRow = !!visible;
51 <span id='Ext-grid-feature-AbstractSummary-method-getSummaryFragments'> /**
52 </span> * Gets any fragments to be used in the tpl
54 * @return {Object} The fragments
56 getSummaryFragments: function(){
58 if (this.showSummaryRow) {
59 Ext.apply(fragments, {
60 printSummaryRow: Ext.bind(this.printSummaryRow, this)
66 <span id='Ext-grid-feature-AbstractSummary-method-printSummaryRow'> /**
67 </span> * Prints a summary row
69 * @param {Object} index The index in the template
70 * @return {String} The value of the summary row
72 printSummaryRow: function(index){
73 var inner = this.view.getTableChunker().metaRowTpl.join('');
75 inner = inner.replace('x-grid-row', 'x-grid-row-summary');
76 inner = inner.replace('{{id}}', '{gridSummaryValue}');
77 inner = inner.replace(this.nestedIdRe, '{id$1}');
78 inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
79 inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
80 inner = Ext.create('Ext.XTemplate', inner, {
81 firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
84 return inner.applyTemplate({
85 columns: this.getPrintData(index)
89 <span id='Ext-grid-feature-AbstractSummary-method-getColumnValue'> /**
90 </span> * Gets the value for the column from the attached data.
91 * @param {Ext.grid.column.Column} column The header
92 * @param {Object} data The current data
93 * @return {String} The value to be rendered
95 getColumnValue: function(column, summaryData){
96 var comp = Ext.getCmp(column.id),
97 value = summaryData[column.dataIndex],
98 renderer = comp.summaryRenderer;
101 value = renderer.call(
111 <span id='Ext-grid-feature-AbstractSummary-method-getSummary'> /**
112 </span> * Get the summary data for a field.
114 * @param {Ext.data.Store} store The store to get the data from
115 * @param {String/Function} type The type of aggregation. If a function is specified it will
116 * be passed to the stores aggregate function.
117 * @param {String} field The field to aggregate on
118 * @param {Boolean} group True to aggregate in grouped mode
119 * @return {Mixed} See the return type for the store functions.
121 getSummary: function(store, type, field, group){
123 if (Ext.isFunction(type)) {
124 return store.aggregate(type, null, group);
129 return store.count(group);
131 return store.min(field, group);
133 return store.max(field, group);
135 return store.sum(field, group);
137 return store.average(field, group);
139 return group ? {} : '';