AbstractSummary.html
5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-grid-feature-AbstractSummary'>/**
</span> * A small abstract class that contains the shared behaviour for any summary
* calculations to be used in the grid.
*/
Ext.define('Ext.grid.feature.AbstractSummary', {
/* Begin Definitions */
extend: 'Ext.grid.feature.Feature',
alias: 'feature.abstractsummary',
/* End Definitions */
<span id='Ext-grid-feature-AbstractSummary-cfg-showSummaryRow'> /**
</span> * @cfg
* True to show the summary row.
*/
showSummaryRow: true,
// @private
nestedIdRe: /\{\{id\}([\w\-]*)\}/g,
// Listen for store updates. Eg, from an Editor.
init: function() {
var me = this;
// Summary rows must be kept in column order, so view must be refreshed on column move
me.grid.optimizedColumnMove = false;
me.view.mon(me.view.store, {
update: me.onStoreUpdate,
scope: me
});
},
// Refresh the whole view on edit so that the Summary gets updated
onStoreUpdate: function() {
var v = this.view;
if (this.showSummaryRow) {
v.saveScrollState();
v.refresh();
v.restoreScrollState();
}
},
<span id='Ext-grid-feature-AbstractSummary-method-toggleSummaryRow'> /**
</span> * Toggle whether or not to show the summary row.
* @param {Boolean} visible True to show the summary row
*/
toggleSummaryRow: function(visible){
this.showSummaryRow = !!visible;
},
<span id='Ext-grid-feature-AbstractSummary-method-getSummaryFragments'> /**
</span> * Gets any fragments to be used in the tpl
* @private
* @return {Object} The fragments
*/
getSummaryFragments: function(){
var fragments = {};
if (this.showSummaryRow) {
Ext.apply(fragments, {
printSummaryRow: Ext.bind(this.printSummaryRow, this)
});
}
return fragments;
},
<span id='Ext-grid-feature-AbstractSummary-method-printSummaryRow'> /**
</span> * Prints a summary row
* @private
* @param {Object} index The index in the template
* @return {String} The value of the summary row
*/
printSummaryRow: function(index){
var inner = this.view.getTableChunker().metaRowTpl.join(''),
prefix = Ext.baseCSSPrefix;
inner = inner.replace(prefix + 'grid-row', prefix + 'grid-row-summary');
inner = inner.replace('{{id}}', '{gridSummaryValue}');
inner = inner.replace(this.nestedIdRe, '{id$1}');
inner = inner.replace('{[this.embedRowCls()]}', '{rowCls}');
inner = inner.replace('{[this.embedRowAttr()]}', '{rowAttr}');
inner = new Ext.XTemplate(inner, {
firstOrLastCls: Ext.view.TableChunker.firstOrLastCls
});
return inner.applyTemplate({
columns: this.getPrintData(index)
});
},
<span id='Ext-grid-feature-AbstractSummary-method-getColumnValue'> /**
</span> * Gets the value for the column from the attached data.
* @param {Ext.grid.column.Column} column The header
* @param {Object} data The current data
* @return {String} The value to be rendered
*/
getColumnValue: function(column, summaryData){
var comp = Ext.getCmp(column.id),
value = summaryData[column.id],
renderer = comp.summaryRenderer;
if (!value && value !== 0) {
value = '\u00a0';
}
if (renderer) {
value = renderer.call(
comp.scope || this,
value,
summaryData,
column.dataIndex
);
}
return value;
},
<span id='Ext-grid-feature-AbstractSummary-method-getSummary'> /**
</span> * Get the summary data for a field.
* @private
* @param {Ext.data.Store} store The store to get the data from
* @param {String/Function} type The type of aggregation. If a function is specified it will
* be passed to the stores aggregate function.
* @param {String} field The field to aggregate on
* @param {Boolean} group True to aggregate in grouped mode
* @return {Number/String/Object} See the return type for the store functions.
*/
getSummary: function(store, type, field, group){
if (type) {
if (Ext.isFunction(type)) {
return store.aggregate(type, null, group);
}
switch (type) {
case 'count':
return store.count(group);
case 'min':
return store.min(field, group);
case 'max':
return store.max(field, group);
case 'sum':
return store.sum(field, group);
case 'average':
return store.average(field, group);
default:
return group ? {} : '';
}
}
}
});
</pre>
</body>
</html>