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