4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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
53 * Ext.define('TestResult', {
54 * extend: 'Ext.data.Model',
55 * fields: ['student', {
61 * Ext.create('Ext.grid.Panel', {
64 * renderTo: document.body,
69 * model: 'TestResult',
71 * student: 'Student 1',
74 * student: 'Student 2',
77 * student: 'Student 3',
80 * student: 'Student 4',
85 * dataIndex: 'student',
87 * summaryType: 'count',
88 * summaryRenderer: function(value, summaryData, dataIndex) {
89 * return Ext.String.format('{0} student{1}', value, value !== 1 ? 's' : '');
94 * summaryType: 'average'
98 Ext.define('Ext.grid.feature.Summary', {
100 /* Begin Definitions */
102 extend: 'Ext.grid.feature.AbstractSummary',
104 alias: 'feature.summary',
106 /* End Definitions */
108 <span id='Ext-grid-feature-Summary-method-getFragmentTpl'> /**
109 </span> * Gets any fragments needed for the template.
111 * @return {Object} The fragments
113 getFragmentTpl: function() {
114 // this gets called before render, so we'll setup the data here.
115 this.summaryData = this.generateSummaryData();
116 return this.getSummaryFragments();
119 <span id='Ext-grid-feature-Summary-method-getTableFragments'> /**
120 </span> * Overrides the closeRows method on the template so we can include our own custom
123 * @return {Object} The custom fragments
125 getTableFragments: function(){
126 if (this.showSummaryRow) {
128 closeRows: this.closeRows
133 <span id='Ext-grid-feature-Summary-method-closeRows'> /**
134 </span> * Provide our own custom footer for the grid.
136 * @return {String} The custom footer
138 closeRows: function() {
139 return '</tpl>{[this.printSummaryRow()]}';
142 <span id='Ext-grid-feature-Summary-method-getPrintData'> /**
143 </span> * Gets the data for printing a template row
145 * @param {Number} index The index in the template
146 * @return {Array} The template values
148 getPrintData: function(index){
150 columns = me.view.headerCt.getColumnsForTpl(),
152 length = columns.length,
154 active = me.summaryData,
157 for (; i < length; ++i) {
159 column.gridSummaryValue = this.getColumnValue(column, active);
165 <span id='Ext-grid-feature-Summary-method-generateSummaryData'> /**
166 </span> * Generates all of the summary data to be used when processing the template
168 * @return {Object} The summary data
170 generateSummaryData: function(){
173 store = me.view.store,
174 columns = me.view.headerCt.getColumnsForTpl(),
176 length = columns.length,
181 for (i = 0, length = columns.length; i < length; ++i) {
182 comp = Ext.getCmp(columns[i].id);
183 data[comp.id] = me.getSummary(store, comp.summaryType, comp.dataIndex, false);