Upgrade to ExtJS 4.0.1 - Released 05/18/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> * A small abstract class that contains the shared behaviour for any summary
20  * calculations to be used in the grid.
21  * @class Ext.grid.feature.AbstractSummary
22  * @extends Ext.grid.feature.Feature
23  * @ignore
24  */
25 Ext.define('Ext.grid.feature.AbstractSummary', {
26     
27     /* Begin Definitions */
28    
29     extend: 'Ext.grid.feature.Feature',
30     
31     alias: 'feature.abstractsummary',
32    
33     /* End Definitions */
34    
35 <span id='Ext-grid-feature-AbstractSummary-cfg-showSummaryRow'>   /**
36 </span>    * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to &lt;tt&gt;true&lt;/tt&gt;.
37     */
38     showSummaryRow: true,
39     
40     // @private
41     nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
42     
43 <span id='Ext-grid-feature-AbstractSummary-method-toggleSummaryRow'>    /**
44 </span>     * Toggle whether or not to show the summary row.
45      * @param {Boolan} visible True to show the summary row
46      */
47     toggleSummaryRow: function(visible){
48         this.showSummaryRow = !!visible;
49     },
50     
51 <span id='Ext-grid-feature-AbstractSummary-method-getSummaryFragments'>    /**
52 </span>     * Gets any fragments to be used in the tpl
53      * @private
54      * @return {Object} The fragments
55      */
56     getSummaryFragments: function(){
57         var fragments = {};
58         if (this.showSummaryRow) {
59             Ext.apply(fragments, {
60                 printSummaryRow: Ext.bind(this.printSummaryRow, this)
61             });
62         }
63         return fragments;
64     },
65     
66 <span id='Ext-grid-feature-AbstractSummary-method-printSummaryRow'>    /**
67 </span>     * Prints a summary row
68      * @private
69      * @param {Object} index The index in the template
70      * @return {String} The value of the summary row
71      */
72     printSummaryRow: function(index){
73         var inner = this.view.getTableChunker().metaRowTpl.join('');
74         
75         inner = inner.replace('x-grid-row', 'x-grid-row-summary');
76         inner = inner.replace('{{id}}', '{gridSummaryValue}');
77         inner = inner.replace(this.nestedIdRe, '{id$1}');  
78         inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
79         inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
80         inner = Ext.create('Ext.XTemplate', inner, {
81             firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
82         });
83         
84         return inner.applyTemplate({
85             columns: this.getPrintData(index)
86         });
87     },
88     
89 <span id='Ext-grid-feature-AbstractSummary-method-getColumnValue'>    /**
90 </span>     * Gets the value for the column from the attached data.
91      * @param {Ext.grid.column.Column} column The header
92      * @param {Object} data The current data
93      * @return {String} The value to be rendered
94      */
95     getColumnValue: function(column, summaryData){
96         var comp     = Ext.getCmp(column.id),
97             value    = summaryData[column.dataIndex],
98             renderer = comp.summaryRenderer;
99
100         if (renderer) {
101             value = renderer.call(
102                 comp.scope || this,
103                 value,
104                 summaryData,
105                 column.dataIndex
106             );
107         }
108         return value;
109     },
110     
111 <span id='Ext-grid-feature-AbstractSummary-method-getSummary'>    /**
112 </span>     * Get the summary data for a field.
113      * @private
114      * @param {Ext.data.Store} store The store to get the data from
115      * @param {String/Function} type The type of aggregation. If a function is specified it will
116      * be passed to the stores aggregate function.
117      * @param {String} field The field to aggregate on
118      * @param {Boolean} group True to aggregate in grouped mode 
119      * @return {Mixed} See the return type for the store functions.
120      */
121     getSummary: function(store, type, field, group){
122         if (type) {
123             if (Ext.isFunction(type)) {
124                 return store.aggregate(type, null, group);
125             }
126             
127             switch (type) {
128                 case 'count':
129                     return store.count(group);
130                 case 'min':
131                     return store.min(field, group);
132                 case 'max':
133                     return store.max(field, group);
134                 case 'sum':
135                     return store.sum(field, group);
136                 case 'average':
137                     return store.average(field, group);
138                 default:
139                     return group ? {} : '';
140                     
141             }
142         }
143     }
144     
145 });
146 </pre>
147 </body>
148 </html>