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> * @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 {Boolan} 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('');
74 inner = inner.replace('x-grid-row', 'x-grid-row-summary');
75 inner = inner.replace('{{id}}', '{gridSummaryValue}');
76 inner = inner.replace(this.nestedIdRe, '{id$1}');
77 inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
78 inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
79 inner = Ext.create('Ext.XTemplate', inner, {
80 firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
83 return inner.applyTemplate({
84 columns: this.getPrintData(index)
88 <span id='Ext-grid-feature-AbstractSummary-method-getColumnValue'> /**
89 </span> * Gets the value for the column from the attached data.
90 * @param {Ext.grid.column.Column} column The header
91 * @param {Object} data The current data
92 * @return {String} The value to be rendered
94 getColumnValue: function(column, summaryData){
95 var comp = Ext.getCmp(column.id),
96 value = summaryData[column.id],
97 renderer = comp.summaryRenderer;
100 value = renderer.call(
110 <span id='Ext-grid-feature-AbstractSummary-method-getSummary'> /**
111 </span> * Get the summary data for a field.
113 * @param {Ext.data.Store} store The store to get the data from
114 * @param {String/Function} type The type of aggregation. If a function is specified it will
115 * be passed to the stores aggregate function.
116 * @param {String} field The field to aggregate on
117 * @param {Boolean} group True to aggregate in grouped mode
118 * @return {Mixed} See the return type for the store functions.
120 getSummary: function(store, type, field, group){
122 if (Ext.isFunction(type)) {
123 return store.aggregate(type, null, group);
128 return store.count(group);
130 return store.min(field, group);
132 return store.max(field, group);
134 return store.sum(field, group);
136 return store.average(field, group);
138 return group ? {} : '';