]> git.proxmox.com Git - extjs.git/blob - extjs/examples/classic/grid/group-summary-grid.js
add extjs 6.0.1 sources
[extjs.git] / extjs / examples / classic / grid / group-summary-grid.js
1 Ext.require([
2 'Ext.grid.*',
3 'Ext.data.*',
4 'Ext.form.field.Number',
5 'Ext.form.field.Date',
6 'Ext.tip.QuickTipManager'
7 ]);
8
9 Ext.define('Task', {
10 extend: 'Ext.data.Model',
11 idProperty: 'taskId',
12 fields: [
13 {name: 'projectId', type: 'int'},
14 {name: 'project', type: 'string'},
15 {name: 'taskId', type: 'int'},
16 {name: 'description', type: 'string'},
17 {name: 'estimate', type: 'float'},
18 {name: 'rate', type: 'float'},
19 {name: 'cost', type: 'float'},
20 {name: 'due', type: 'date', dateFormat:'m/d/Y'}
21 ]
22 });
23
24 var data = [
25 {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 112, description: 'Integrate 2.0 Forms with 2.0 Layouts', estimate: 6, rate: 150, due:'06/24/2007'},
26 {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 113, description: 'Implement AnchorLayout', estimate: 4, rate: 150, due:'06/25/2007'},
27 {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 114, description: 'Add support for multiple types of anchors', estimate: 4, rate: 150, due:'06/27/2007'},
28 {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 115, description: 'Testing and debugging', estimate: 8, rate: 0, due:'06/29/2007'},
29 {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 101, description: 'Add required rendering "hooks" to GridView', estimate: 6, rate: 100, due:'07/01/2007'},
30 {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 102, description: 'Extend GridView and override rendering functions', estimate: 6, rate: 100, due:'07/03/2007'},
31 {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 103, description: 'Extend Store with grouping functionality', estimate: 4, rate: 100, due:'07/04/2007'},
32 {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 121, description: 'Default CSS Styling', estimate: 2, rate: 100, due:'07/05/2007'},
33 {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 104, description: 'Testing and debugging', estimate: 6, rate: 100, due:'07/06/2007'},
34 {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 105, description: 'Ext Grid plugin integration', estimate: 4, rate: 125, due:'07/01/2007'},
35 {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 106, description: 'Summary creation during rendering phase', estimate: 4, rate: 125, due:'07/02/2007'},
36 {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 107, description: 'Dynamic summary updates in editor grids', estimate: 6, rate: 125, due:'07/05/2007'},
37 {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 108, description: 'Remote summary integration', estimate: 4, rate: 125, due:'07/05/2007'},
38 {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 109, description: 'Summary renderers and calculators', estimate: 4, rate: 125, due:'07/06/2007'},
39 {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 110, description: 'Integrate summaries with GroupingView', estimate: 10, rate: 125, due:'07/11/2007'},
40 {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 111, description: 'Testing and debugging', estimate: 8, rate: 125, due:'07/15/2007'}
41 ];
42
43 Ext.onReady(function(){
44
45 Ext.tip.QuickTipManager.init();
46
47 var store = Ext.create('Ext.data.Store', {
48 model: 'Task',
49 data: data,
50 sorters: {property: 'due', direction: 'ASC'},
51 groupField: 'project'
52 });
53
54 var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
55 clicksToEdit: 1
56 });
57
58 var grid = Ext.create('Ext.grid.Panel', {
59 width: 840,
60 height: 450,
61 frame: true,
62 title: 'Sponsored Projects',
63 iconCls: 'icon-grid',
64 renderTo: document.body,
65 store: store,
66 plugins: [cellEditing],
67 dockedItems: [{
68 dock: 'top',
69 xtype: 'toolbar',
70 items: [{
71 tooltip: 'Toggle the visibility of the summary row',
72 text: 'Toggle Summary',
73 enableToggle: true,
74 pressed: true,
75 handler: function() {
76 grid.getView().getFeature('group').toggleSummaryRow();
77 }
78 }]
79 }],
80 features: [{
81 id: 'group',
82 ftype: 'groupingsummary',
83 groupHeaderTpl: '{name}',
84 hideGroupedHeader: true,
85 enableGroupingMenu: false
86 }],
87 columns: [{
88 text: 'Task',
89 flex: 1,
90 tdCls: 'task',
91 sortable: true,
92 dataIndex: 'description',
93 hideable: false,
94 summaryType: 'count',
95 summaryRenderer: function(value, summaryData, dataIndex) {
96 return ((value === 0 || value > 1) ? '(' + value + ' Tasks)' : '(1 Task)');
97 }
98 }, {
99 header: 'Project',
100 width: 180,
101 sortable: true,
102 dataIndex: 'project'
103 }, {
104 header: 'Due Date',
105 width: 136,
106 sortable: true,
107 dataIndex: 'due',
108 summaryType: 'max',
109 renderer: Ext.util.Format.dateRenderer('m/d/Y'),
110 summaryRenderer: Ext.util.Format.dateRenderer('m/d/Y'),
111 field: {
112 xtype: 'datefield'
113 }
114 }, {
115 header: 'Estimate',
116 width: 100,
117 sortable: true,
118 dataIndex: 'estimate',
119 summaryType: 'sum',
120 renderer: function(value, metaData, record, rowIdx, colIdx, store, view){
121 return value + ' hours';
122 },
123 summaryRenderer: function(value, summaryData, dataIndex) {
124 return value + ' hours';
125 },
126 field: {
127 xtype: 'numberfield'
128 }
129 }, {
130 header: 'Rate',
131 width: 120,
132 sortable: true,
133 renderer: Ext.util.Format.usMoney,
134 summaryRenderer: Ext.util.Format.usMoney,
135 dataIndex: 'rate',
136 summaryType: 'average',
137 field: {
138 xtype: 'numberfield'
139 }
140 }, {
141 id: 'cost',
142 header: 'Cost',
143 width: 100,
144 sortable: false,
145 groupable: false,
146 renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {
147 return Ext.util.Format.usMoney(record.get('estimate') * record.get('rate'));
148 },
149 dataIndex: 'cost',
150 summaryType: function(records, values) {
151 var i = 0,
152 length = records.length,
153 total = 0,
154 record;
155
156 for (; i < length; ++i) {
157 record = records[i];
158 total += record.get('estimate') * record.get('rate');
159 }
160 return total;
161 },
162 summaryRenderer: Ext.util.Format.usMoney
163 }]
164 });
165 });