2 * A small abstract class that contains the shared behaviour for any summary
3 * calculations to be used in the grid.
4 * @class Ext.grid.feature.AbstractSummary
5 * @extends Ext.grid.feature.Feature
8 Ext.define('Ext.grid.feature.AbstractSummary', {
10 /* Begin Definitions */
12 extend: 'Ext.grid.feature.Feature',
14 alias: 'feature.abstractsummary',
19 * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to <tt>true</tt>.
24 nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
27 * Toggle whether or not to show the summary row.
28 * @param {Boolan} visible True to show the summary row
30 toggleSummaryRow: function(visible){
31 this.showSummaryRow = !!visible;
35 * Gets any fragments to be used in the tpl
37 * @return {Object} The fragments
39 getSummaryFragments: function(){
41 if (this.showSummaryRow) {
42 Ext.apply(fragments, {
43 printSummaryRow: Ext.bind(this.printSummaryRow, this)
50 * Prints a summary row
52 * @param {Object} index The index in the template
53 * @return {String} The value of the summary row
55 printSummaryRow: function(index){
56 var inner = this.view.getTableChunker().metaRowTpl.join('');
58 inner = inner.replace('x-grid-row', 'x-grid-row-summary');
59 inner = inner.replace('{{id}}', '{gridSummaryValue}');
60 inner = inner.replace(this.nestedIdRe, '{id$1}');
61 inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
62 inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
63 inner = Ext.create('Ext.XTemplate', inner, {
64 firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
67 return inner.applyTemplate({
68 columns: this.getPrintData(index)
73 * Gets the value for the column from the attached data.
74 * @param {Ext.grid.column.Column} column The header
75 * @param {Object} data The current data
76 * @return {String} The value to be rendered
78 getColumnValue: function(column, summaryData){
79 var comp = Ext.getCmp(column.id),
80 value = summaryData[column.dataIndex],
81 renderer = comp.summaryRenderer;
84 value = renderer.call(
95 * Get the summary data for a field.
97 * @param {Ext.data.Store} store The store to get the data from
98 * @param {String/Function} type The type of aggregation. If a function is specified it will
99 * be passed to the stores aggregate function.
100 * @param {String} field The field to aggregate on
101 * @param {Boolean} group True to aggregate in grouped mode
102 * @return {Mixed} See the return type for the store functions.
104 getSummary: function(store, type, field, group){
106 if (Ext.isFunction(type)) {
107 return store.aggregate(type, null, group);
112 return store.count(group);
114 return store.min(field, group);
116 return store.max(field, group);
118 return store.sum(field, group);
120 return store.average(field, group);
122 return group ? {} : '';