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; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-grid-feature-Summary'>/**
19 </span> * @class Ext.grid.feature.Summary
20 * @extends Ext.grid.feature.AbstractSummary
22 * This feature is used to place a summary row at the bottom of the grid. If using a grouping,
23 * see {@link Ext.grid.feature.GroupingSummary}. There are 2 aspects to calculating the summaries,
24 * calculation and rendering.
27 * The summary value needs to be calculated for each column in the grid. This is controlled
28 * by the summaryType option specified on the column. There are several built in summary types,
29 * which can be specified as a string on the column configuration. These call underlying methods
32 * - {@link Ext.data.Store#count count}
33 * - {@link Ext.data.Store#sum sum}
34 * - {@link Ext.data.Store#min min}
35 * - {@link Ext.data.Store#max max}
36 * - {@link Ext.data.Store#average average}
38 * Alternatively, the summaryType can be a function definition. If this is the case,
39 * the function is called with an array of records to calculate the summary value.
42 * Similar to a column, the summary also supports a summaryRenderer function. This
43 * summaryRenderer is called before displaying a value. The function is optional, if
44 * not specified the default calculated value is shown. The summaryRenderer is called with:
46 * - value {Object} - The calculated value.
47 * - summaryData {Object} - Contains all raw summary values for the row.
48 * - field {String} - The name of the field we are calculating
52 * Ext.define('TestResult', {
53 * extend: 'Ext.data.Model',
54 * fields: ['student', {
60 * Ext.create('Ext.grid.Panel', {
63 * renderTo: document.body,
68 * model: 'TestResult',
70 * student: 'Student 1',
73 * student: 'Student 2',
76 * student: 'Student 3',
79 * student: 'Student 4',
84 * dataIndex: 'student',
86 * summaryType: 'count',
87 * summaryRenderer: function(value, summaryData, dataIndex) {
88 * return Ext.String.format('{0} student{1}', value, value !== 1 ? 's' : '');
93 * summaryType: 'average'
97 Ext.define('Ext.grid.feature.Summary', {
99 /* Begin Definitions */
101 extend: 'Ext.grid.feature.AbstractSummary',
103 alias: 'feature.summary',
105 /* End Definitions */
107 <span id='Ext-grid-feature-Summary-method-getFragmentTpl'> /**
108 </span> * Gets any fragments needed for the template.
110 * @return {Object} The fragments
112 getFragmentTpl: function() {
113 // this gets called before render, so we'll setup the data here.
114 this.summaryData = this.generateSummaryData();
115 return this.getSummaryFragments();
118 <span id='Ext-grid-feature-Summary-method-getTableFragments'> /**
119 </span> * Overrides the closeRows method on the template so we can include our own custom
122 * @return {Object} The custom fragments
124 getTableFragments: function(){
125 if (this.showSummaryRow) {
127 closeRows: this.closeRows
132 <span id='Ext-grid-feature-Summary-method-closeRows'> /**
133 </span> * Provide our own custom footer for the grid.
135 * @return {String} The custom footer
137 closeRows: function() {
138 return '</tpl>{[this.printSummaryRow()]}';
141 <span id='Ext-grid-feature-Summary-method-getPrintData'> /**
142 </span> * Gets the data for printing a template row
144 * @param {Number} index The index in the template
145 * @return {Array} The template values
147 getPrintData: function(index){
149 columns = me.view.headerCt.getColumnsForTpl(),
151 length = columns.length,
153 active = me.summaryData,
156 for (; i < length; ++i) {
158 column.gridSummaryValue = this.getColumnValue(column, active);
164 <span id='Ext-grid-feature-Summary-method-generateSummaryData'> /**
165 </span> * Generates all of the summary data to be used when processing the template
167 * @return {Object} The summary data
169 generateSummaryData: function(){
172 store = me.view.store,
173 columns = me.view.headerCt.getColumnsForTpl(),
175 length = columns.length,
180 for (i = 0, length = columns.length; i < length; ++i) {
181 comp = Ext.getCmp(columns[i].id);
182 data[comp.dataIndex] = me.getSummary(store, comp.summaryType, comp.dataIndex, false);