3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.grid.feature.AbstractSummary
17 * @extends Ext.grid.feature.Feature
18 * A small abstract class that contains the shared behaviour for any summary
19 * calculations to be used in the grid.
21 Ext.define('Ext.grid.feature.AbstractSummary', {
23 /* Begin Definitions */
25 extend: 'Ext.grid.feature.Feature',
27 alias: 'feature.abstractsummary',
32 * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to <tt>true</tt>.
37 nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
40 * Toggle whether or not to show the summary row.
41 * @param {Boolean} visible True to show the summary row
43 toggleSummaryRow: function(visible){
44 this.showSummaryRow = !!visible;
48 * Gets any fragments to be used in the tpl
50 * @return {Object} The fragments
52 getSummaryFragments: function(){
54 if (this.showSummaryRow) {
55 Ext.apply(fragments, {
56 printSummaryRow: Ext.bind(this.printSummaryRow, this)
63 * Prints a summary row
65 * @param {Object} index The index in the template
66 * @return {String} The value of the summary row
68 printSummaryRow: function(index){
69 var inner = this.view.getTableChunker().metaRowTpl.join(''),
70 prefix = Ext.baseCSSPrefix;
72 inner = inner.replace(prefix + 'grid-row', prefix + 'grid-row-summary');
73 inner = inner.replace('{{id}}', '{gridSummaryValue}');
74 inner = inner.replace(this.nestedIdRe, '{id$1}');
75 inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
76 inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
77 inner = Ext.create('Ext.XTemplate', inner, {
78 firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
81 return inner.applyTemplate({
82 columns: this.getPrintData(index)
87 * Gets the value for the column from the attached data.
88 * @param {Ext.grid.column.Column} column The header
89 * @param {Object} data The current data
90 * @return {String} The value to be rendered
92 getColumnValue: function(column, summaryData){
93 var comp = Ext.getCmp(column.id),
94 value = summaryData[column.id],
95 renderer = comp.summaryRenderer;
98 value = renderer.call(
109 * Get the summary data for a field.
111 * @param {Ext.data.Store} store The store to get the data from
112 * @param {String/Function} type The type of aggregation. If a function is specified it will
113 * be passed to the stores aggregate function.
114 * @param {String} field The field to aggregate on
115 * @param {Boolean} group True to aggregate in grouped mode
116 * @return {Number/String/Object} See the return type for the store functions.
118 getSummary: function(store, type, field, group){
120 if (Ext.isFunction(type)) {
121 return store.aggregate(type, null, group);
126 return store.count(group);
128 return store.min(field, group);
130 return store.max(field, group);
132 return store.sum(field, group);
134 return store.average(field, group);
136 return group ? {} : '';