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
8 Ext.define('Ext.grid.feature.AbstractSummary', {
10 /* Begin Definitions */
12 extend: 'Ext.grid.feature.Feature',
14 alias: 'feature.abstractsummary',
18 <span id='Ext-grid.feature.AbstractSummary-cfg-showSummaryRow'> /**
19 </span> * @cfg {Boolean} showSummaryRow True to show the summary row. Defaults to <tt>true</tt>.
24 nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
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
30 toggleSummaryRow: function(visible){
31 this.showSummaryRow = !!visible;
34 <span id='Ext-grid.feature.AbstractSummary-method-getSummaryFragments'> /**
35 </span> * 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)
49 <span id='Ext-grid.feature.AbstractSummary-method-printSummaryRow'> /**
50 </span> * 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)
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
78 getColumnValue: function(column, data){
79 var comp = Ext.getCmp(column.id),
80 value = data[column.dataIndex],
81 renderer = comp.summaryRenderer || comp.renderer;
84 value = renderer.call(comp.scope || this, value, data, column.dataIndex);
89 <span id='Ext-grid.feature.AbstractSummary-method-getSummary'> /**
90 </span> * Get the summary data for a field.
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.
99 getSummary: function(store, type, field, group){
101 if (Ext.isFunction(type)) {
102 return store.aggregate(type, null, group);
107 return store.count(group);
109 return store.min(field, group);
111 return store.max(field, group);
113 return store.sum(field, group);
115 return store.average(field, group);
117 return group ? {} : '';
124 </pre></pre></body></html>