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; }
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> * @class Ext.grid.feature.AbstractSummary
20 * @extends Ext.grid.feature.Feature
21 * A small abstract class that contains the shared behaviour for any summary
22 * calculations to be used in the grid.
24 Ext.define('Ext.grid.feature.AbstractSummary', {
26 /* Begin Definitions */
28 extend: 'Ext.grid.feature.Feature',
30 alias: 'feature.abstractsummary',
34 <span id='Ext-grid-feature-AbstractSummary-cfg-showSummaryRow'> /**
35 </span> * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to <tt>true</tt>.
40 nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
42 <span id='Ext-grid-feature-AbstractSummary-method-toggleSummaryRow'> /**
43 </span> * Toggle whether or not to show the summary row.
44 * @param {Boolean} visible True to show the summary row
46 toggleSummaryRow: function(visible){
47 this.showSummaryRow = !!visible;
50 <span id='Ext-grid-feature-AbstractSummary-method-getSummaryFragments'> /**
51 </span> * Gets any fragments to be used in the tpl
53 * @return {Object} The fragments
55 getSummaryFragments: function(){
57 if (this.showSummaryRow) {
58 Ext.apply(fragments, {
59 printSummaryRow: Ext.bind(this.printSummaryRow, this)
65 <span id='Ext-grid-feature-AbstractSummary-method-printSummaryRow'> /**
66 </span> * Prints a summary row
68 * @param {Object} index The index in the template
69 * @return {String} The value of the summary row
71 printSummaryRow: function(index){
72 var inner = this.view.getTableChunker().metaRowTpl.join(''),
73 prefix = Ext.baseCSSPrefix;
75 inner = inner.replace(prefix + 'grid-row', prefix + '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.id],
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 {Number/String/Object} 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 ? {} : '';