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 {Boolan} 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('');
71 inner = inner.replace('x-grid-row', 'x-grid-row-summary');
72 inner = inner.replace('{{id}}', '{gridSummaryValue}');
73 inner = inner.replace(this.nestedIdRe, '{id$1}');
74 inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
75 inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
76 inner = Ext.create('Ext.XTemplate', inner, {
77 firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
80 return inner.applyTemplate({
81 columns: this.getPrintData(index)
86 * Gets the value for the column from the attached data.
87 * @param {Ext.grid.column.Column} column The header
88 * @param {Object} data The current data
89 * @return {String} The value to be rendered
91 getColumnValue: function(column, summaryData){
92 var comp = Ext.getCmp(column.id),
93 value = summaryData[column.id],
94 renderer = comp.summaryRenderer;
97 value = renderer.call(
108 * Get the summary data for a field.
110 * @param {Ext.data.Store} store The store to get the data from
111 * @param {String/Function} type The type of aggregation. If a function is specified it will
112 * be passed to the stores aggregate function.
113 * @param {String} field The field to aggregate on
114 * @param {Boolean} group True to aggregate in grouped mode
115 * @return {Mixed} See the return type for the store functions.
117 getSummary: function(store, type, field, group){
119 if (Ext.isFunction(type)) {
120 return store.aggregate(type, null, group);
125 return store.count(group);
127 return store.min(field, group);
129 return store.max(field, group);
131 return store.sum(field, group);
133 return store.average(field, group);
135 return group ? {} : '';