Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / AbstractSummary.html
1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-grid.feature.AbstractSummary'>/**
2 </span> * 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
6  * @ignore
7  */
8 Ext.define('Ext.grid.feature.AbstractSummary', {
9     
10     /* Begin Definitions */
11    
12     extend: 'Ext.grid.feature.Feature',
13     
14     alias: 'feature.abstractsummary',
15    
16     /* End Definitions */
17    
18 <span id='Ext-grid.feature.AbstractSummary-cfg-showSummaryRow'>   /**
19 </span>    * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to &lt;tt&gt;true&lt;/tt&gt;.
20     */
21     showSummaryRow: true,
22     
23     // @private
24     nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
25     
26 <span id='Ext-grid.feature.AbstractSummary-method-toggleSummaryRow'>    /**
27 </span>     * Toggle whether or not to show the summary row.
28      * @param {Boolan} visible True to show the summary row
29      */
30     toggleSummaryRow: function(visible){
31         this.showSummaryRow = !!visible;
32     },
33     
34 <span id='Ext-grid.feature.AbstractSummary-method-getSummaryFragments'>    /**
35 </span>     * Gets any fragments to be used in the tpl
36      * @private
37      * @return {Object} The fragments
38      */
39     getSummaryFragments: function(){
40         var fragments = {};
41         if (this.showSummaryRow) {
42             Ext.apply(fragments, {
43                 printSummaryRow: Ext.bind(this.printSummaryRow, this)
44             });
45         }
46         return fragments;
47     },
48     
49 <span id='Ext-grid.feature.AbstractSummary-method-printSummaryRow'>    /**
50 </span>     * Prints a summary row
51      * @private
52      * @param {Object} index The index in the template
53      * @return {String} The value of the summary row
54      */
55     printSummaryRow: function(index){
56         var inner = this.view.getTableChunker().metaRowTpl.join('');
57         
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
65         });
66         
67         return inner.applyTemplate({
68             columns: this.getPrintData(index)
69         });
70     },
71     
72 <span id='Ext-grid.feature.AbstractSummary-method-getColumnValue'>    /**
73 </span>     * 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
77      */
78     getColumnValue: function(column, data){
79         var comp = Ext.getCmp(column.id),
80             value = data[column.dataIndex],
81             renderer = comp.summaryRenderer || comp.renderer;
82             
83         if (renderer) {
84             value = renderer.call(comp.scope || this, value, data, column.dataIndex);
85         }
86         return value;
87     },
88     
89 <span id='Ext-grid.feature.AbstractSummary-method-getSummary'>    /**
90 </span>     * Get the summary data for a field.
91      * @private
92      * @param {Ext.data.Store} store The store to get the data from
93      * @param {String/Function} type The type of aggregation. If a function is specified it will
94      * be passed to the stores aggregate function.
95      * @param {String} field The field to aggregate on
96      * @param {Boolean} group True to aggregate in grouped mode 
97      * @return {Mixed} See the return type for the store functions.
98      */
99     getSummary: function(store, type, field, group){
100         if (type) {
101             if (Ext.isFunction(type)) {
102                 return store.aggregate(type, null, group);
103             }
104             
105             switch (type) {
106                 case 'count':
107                     return store.count(group);
108                 case 'min':
109                     return store.min(field, group);
110                 case 'max':
111                     return store.max(field, group);
112                 case 'sum':
113                     return store.sum(field, group);
114                 case 'average':
115                     return store.average(field, group);
116                 default:
117                     return group ? {} : '';
118                     
119             }
120         }
121     }
122     
123 });
124 </pre></pre></body></html>