]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.Loader.setConfig({\r |
2 | enabled: true\r | |
3 | });\r | |
4 | \r | |
5 | Ext.require([\r | |
6 | 'Ext.grid.*',\r | |
7 | 'Ext.layout.container.Border',\r | |
8 | 'Ext.data.*',\r | |
9 | 'Ext.form.field.Number',\r | |
10 | 'Ext.form.field.Date',\r | |
11 | 'Ext.tip.QuickTipManager',\r | |
12 | 'Ext.ux.DataTip'\r | |
13 | ]);\r | |
14 | \r | |
15 | Ext.define('Task', {\r | |
16 | extend: 'Ext.data.Model',\r | |
17 | idProperty: 'taskId',\r | |
18 | fields: [\r | |
19 | {name: 'projectId', type: 'int'},\r | |
20 | {name: 'project', type: 'string'},\r | |
21 | {name: 'taskId', type: 'int'},\r | |
22 | {name: 'description', type: 'string'},\r | |
23 | {name: 'estimate', type: 'float'},\r | |
24 | {name: 'rate', type: 'float'},\r | |
25 | {name: 'due', type: 'date', dateFormat:'m/d/Y'}\r | |
26 | ]\r | |
27 | });\r | |
28 | \r | |
29 | var data = [\r | |
30 | {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 | |
31 | {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 113, description: 'Implement AnchorLayout', estimate: 4, rate: 150, due:'06/25/2007'},\r | |
32 | {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 114, description: 'Add support for multiple<br>types of anchors', estimate: 4, rate: 150, due:'06/27/2007'},\r | |
33 | {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 115, description: 'Testing and debugging', estimate: 8, rate: 0, due:'06/29/2007'},\r | |
34 | {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 | |
35 | {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 | |
36 | {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 | |
37 | {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 121, description: 'Default CSS Styling', estimate: 2, rate: 100, due:'07/05/2007'},\r | |
38 | {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 104, description: 'Testing and debugging', estimate: 6, rate: 100, due:'07/06/2007'},\r | |
39 | {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 105, description: 'Ext Grid plugin integration', estimate: 4, rate: 125, due:'07/01/2007'},\r | |
40 | {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 106, description: 'Summary creation during rendering phase', estimate: 4, rate: 125, due:'07/02/2007'},\r | |
41 | {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 | |
42 | {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 108, description: 'Remote summary integration', estimate: 4, rate: 125, due:'07/05/2007'},\r | |
43 | {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 109, description: 'Summary renderers and calculators', estimate: 4, rate: 125, due:'07/06/2007'},\r | |
44 | {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 110, description: 'Integrate summaries with GroupingView', estimate: 10, rate: 125, due:'07/11/2007'},\r | |
45 | {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 111, description: 'Testing and debugging', estimate: 8, rate: 125, due:'07/15/2007'}\r | |
46 | ];\r | |
47 | \r | |
48 | Ext.onReady(function(){\r | |
49 | \r | |
50 | Ext.tip.QuickTipManager.init();\r | |
51 | \r | |
52 | var store = Ext.create('Ext.data.Store', {\r | |
53 | model: 'Task',\r | |
54 | data: data,\r | |
55 | sorters: {property: 'due', direction: 'ASC'},\r | |
56 | groupField: 'project'\r | |
57 | });\r | |
58 | \r | |
59 | var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {\r | |
60 | clicksToEdit: 1\r | |
61 | });\r | |
62 | \r | |
63 | var grid = Ext.create('Ext.grid.Panel', {\r | |
64 | width: 800,\r | |
65 | height: 450,\r | |
66 | frame: true,\r | |
67 | title: 'Sponsored Projects',\r | |
68 | iconCls: 'icon-grid',\r | |
69 | renderTo: document.body,\r | |
70 | columnLines : true,\r | |
71 | store: store,\r | |
72 | layout: 'border',\r | |
73 | plugins: [\r | |
74 | cellEditing,\r | |
75 | {\r | |
76 | ptype: 'datatip',\r | |
77 | tpl: 'Click to edit {description}'\r | |
78 | }\r | |
79 | ],\r | |
80 | listeners: {\r | |
81 | beforeshowtip: function(grid, tip, data) {\r | |
82 | var cellNode = tip.triggerEvent.getTarget(tip.view.getCellSelector());\r | |
83 | if (cellNode) {\r | |
84 | data.colName = tip.view.headerCt.columnManager.getHeaderAtIndex(cellNode.cellIndex).text;\r | |
85 | }\r | |
86 | }\r | |
87 | },\r | |
88 | selModel: {\r | |
89 | selType: 'cellmodel'\r | |
90 | },\r | |
91 | dockedItems: [{\r | |
92 | dock: 'top',\r | |
93 | xtype: 'toolbar',\r | |
94 | items: [{\r | |
95 | tooltip: 'Toggle the visibility of the summary row',\r | |
96 | text: 'Toggle Summary',\r | |
97 | enableToggle: true,\r | |
98 | pressed: true,\r | |
99 | handler: function() {\r | |
100 | grid.lockedGrid.getView().getFeature('group').toggleSummaryRow();\r | |
101 | }\r | |
102 | }]\r | |
103 | }],\r | |
104 | features: [{\r | |
105 | id: 'group',\r | |
106 | ftype: 'groupingsummary',\r | |
107 | groupHeaderTpl: '{name}',\r | |
108 | hideGroupedHeader: true,\r | |
109 | enableGroupingMenu: true\r | |
110 | }, {\r | |
111 | ftype: 'summary',\r | |
112 | dock: 'bottom'\r | |
113 | }],\r | |
114 | split: true,\r | |
115 | lockedGridConfig: {\r | |
116 | header: false,\r | |
117 | collapsible: true,\r | |
118 | width: 300,\r | |
119 | forceFit: true\r | |
120 | },\r | |
121 | lockedViewConfig: {\r | |
122 | scroll: 'horizontal'\r | |
123 | },\r | |
124 | columns: [{\r | |
125 | text: 'Task',\r | |
126 | flex: 1,\r | |
127 | locked: true,\r | |
128 | tdCls: 'task',\r | |
129 | sortable: true,\r | |
130 | dataIndex: 'description',\r | |
131 | \r | |
132 | // This may have wrapped HTML which causes unpredictable row heights\r | |
133 | variableRowHeight: true,\r | |
134 | hideable: false,\r | |
135 | summaryType: 'count',\r | |
136 | summaryRenderer: function(value, summaryData, dataIndex) {\r | |
137 | return ((value === 0 || value > 1) ? '(' + value + ' Tasks)' : '(1 Task)');\r | |
138 | },\r | |
139 | field: {\r | |
140 | xtype: 'textfield'\r | |
141 | }\r | |
142 | }, {\r | |
143 | header: 'Project',\r | |
144 | width: 180,\r | |
145 | sortable: true,\r | |
146 | dataIndex: 'project'\r | |
147 | }, {\r | |
148 | header: 'Schedule',\r | |
149 | columns: [{\r | |
150 | header: 'Due Date',\r | |
151 | width: 125,\r | |
152 | sortable: true,\r | |
153 | dataIndex: 'due',\r | |
154 | summaryType: 'max',\r | |
155 | renderer: Ext.util.Format.dateRenderer('m/d/Y'),\r | |
156 | summaryRenderer: Ext.util.Format.dateRenderer('m/d/Y'),\r | |
157 | field: {\r | |
158 | xtype: 'datefield'\r | |
159 | }\r | |
160 | }, {\r | |
161 | header: 'Estimate',\r | |
162 | width: 125,\r | |
163 | sortable: true,\r | |
164 | dataIndex: 'estimate',\r | |
165 | summaryType: 'sum',\r | |
166 | renderer: function(value, metaData, record, rowIdx, colIdx, store, view){\r | |
167 | return value + ' hours';\r | |
168 | },\r | |
169 | summaryRenderer: function(value, summaryData, dataIndex) {\r | |
170 | return value + ' hours';\r | |
171 | },\r | |
172 | field: {\r | |
173 | xtype: 'numberfield'\r | |
174 | }\r | |
175 | }, {\r | |
176 | header: 'Rate',\r | |
177 | width: 125,\r | |
178 | sortable: true,\r | |
179 | renderer: Ext.util.Format.usMoney,\r | |
180 | summaryRenderer: Ext.util.Format.usMoney,\r | |
181 | dataIndex: 'rate',\r | |
182 | summaryType: 'average',\r | |
183 | field: {\r | |
184 | xtype: 'numberfield'\r | |
185 | }\r | |
186 | }, {\r | |
187 | header: 'Cost',\r | |
188 | width: 114,\r | |
189 | sortable: false,\r | |
190 | groupable: false,\r | |
191 | renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {\r | |
192 | return Ext.util.Format.usMoney(record.get('estimate') * record.get('rate'));\r | |
193 | },\r | |
194 | summaryType: function(records, values) {\r | |
195 | var i = 0,\r | |
196 | length = records.length,\r | |
197 | total = 0,\r | |
198 | record;\r | |
199 | \r | |
200 | for (; i < length; ++i) {\r | |
201 | record = records[i];\r | |
202 | total += record.get('estimate') * record.get('rate');\r | |
203 | }\r | |
204 | return total;\r | |
205 | },\r | |
206 | summaryRenderer: Ext.util.Format.usMoney\r | |
207 | }]\r | |
208 | }]\r | |
209 | });\r | |
210 | });\r |