Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / AbstractSummary.html
1 <!DOCTYPE html>
2 <html>
3 <head>
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; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
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.
23  */
24 Ext.define('Ext.grid.feature.AbstractSummary', {
25     
26     /* Begin Definitions */
27    
28     extend: 'Ext.grid.feature.Feature',
29     
30     alias: 'feature.abstractsummary',
31    
32     /* End Definitions */
33    
34 <span id='Ext-grid-feature-AbstractSummary-cfg-showSummaryRow'>   /**
35 </span>    * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to &lt;tt&gt;true&lt;/tt&gt;.
36     */
37     showSummaryRow: true,
38     
39     // @private
40     nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
41     
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
45      */
46     toggleSummaryRow: function(visible){
47         this.showSummaryRow = !!visible;
48     },
49     
50 <span id='Ext-grid-feature-AbstractSummary-method-getSummaryFragments'>    /**
51 </span>     * Gets any fragments to be used in the tpl
52      * @private
53      * @return {Object} The fragments
54      */
55     getSummaryFragments: function(){
56         var fragments = {};
57         if (this.showSummaryRow) {
58             Ext.apply(fragments, {
59                 printSummaryRow: Ext.bind(this.printSummaryRow, this)
60             });
61         }
62         return fragments;
63     },
64     
65 <span id='Ext-grid-feature-AbstractSummary-method-printSummaryRow'>    /**
66 </span>     * Prints a summary row
67      * @private
68      * @param {Object} index The index in the template
69      * @return {String} The value of the summary row
70      */
71     printSummaryRow: function(index){
72         var inner = this.view.getTableChunker().metaRowTpl.join('');
73         
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
81         });
82         
83         return inner.applyTemplate({
84             columns: this.getPrintData(index)
85         });
86     },
87     
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
93      */
94     getColumnValue: function(column, summaryData){
95         var comp     = Ext.getCmp(column.id),
96             value    = summaryData[column.id],
97             renderer = comp.summaryRenderer;
98
99         if (renderer) {
100             value = renderer.call(
101                 comp.scope || this,
102                 value,
103                 summaryData,
104                 column.dataIndex
105             );
106         }
107         return value;
108     },
109     
110 <span id='Ext-grid-feature-AbstractSummary-method-getSummary'>    /**
111 </span>     * Get the summary data for a field.
112      * @private
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.
119      */
120     getSummary: function(store, type, field, group){
121         if (type) {
122             if (Ext.isFunction(type)) {
123                 return store.aggregate(type, null, group);
124             }
125             
126             switch (type) {
127                 case 'count':
128                     return store.count(group);
129                 case 'min':
130                     return store.min(field, group);
131                 case 'max':
132                     return store.max(field, group);
133                 case 'sum':
134                     return store.sum(field, group);
135                 case 'average':
136                     return store.average(field, group);
137                 default:
138                     return group ? {} : '';
139                     
140             }
141         }
142     }
143     
144 });
145 </pre>
146 </body>
147 </html>