commit extjs-2.2.1
[extjs.git] / examples / grid / totals.js
1 /*\r
2  * Ext JS Library 2.2.1\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 Ext.onReady(function(){\r
10 \r
11     Ext.QuickTips.init();\r
12 \r
13     var xg = Ext.grid;\r
14 \r
15     var reader = new Ext.data.JsonReader({\r
16         idProperty:'taskId',\r
17         fields: [\r
18             {name: 'projectId', type: 'int'},\r
19             {name: 'project', type: 'string'},\r
20             {name: 'taskId', type: 'int'},\r
21             {name: 'description', type: 'string'},\r
22             {name: 'estimate', type: 'float'},\r
23             {name: 'rate', type: 'float'},\r
24             {name: 'cost', type: 'float'},\r
25             {name: 'due', type: 'date', dateFormat:'m/d/Y'}\r
26         ]\r
27 \r
28     });\r
29 \r
30     // define a custom summary function\r
31     Ext.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){\r
32         return v + (record.data.estimate * record.data.rate);\r
33     }\r
34 \r
35     var summary = new Ext.grid.GroupSummary(); \r
36 \r
37     var grid = new xg.EditorGridPanel({\r
38         ds: new Ext.data.GroupingStore({\r
39             reader: reader,\r
40             data: xg.dummyData,\r
41             sortInfo:{field: 'due', direction: "ASC"},\r
42             groupField:'project'\r
43         }),\r
44 \r
45         columns: [\r
46             {\r
47                 id: 'description',\r
48                 header: "Task",\r
49                 width: 80,\r
50                 sortable: true,\r
51                 dataIndex: 'description',\r
52                 summaryType: 'count',\r
53                 hideable: false,\r
54                 summaryRenderer: function(v, params, data){\r
55                     return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');\r
56                 },\r
57                 editor: new Ext.form.TextField({\r
58                    allowBlank: false\r
59                 })\r
60             },{\r
61                 header: "Project",\r
62                 width: 20,\r
63                 sortable: true,\r
64                 dataIndex: 'project'\r
65             },{\r
66                 header: "Due Date",\r
67                 width: 25,\r
68                 sortable: true,\r
69                 dataIndex: 'due',\r
70                 summaryType:'max',\r
71                 renderer: Ext.util.Format.dateRenderer('m/d/Y'),\r
72                 editor: new Ext.form.DateField({\r
73                     format: 'm/d/Y'\r
74                 })\r
75             },{\r
76                 header: "Estimate",\r
77                 width: 20,\r
78                 sortable: true,\r
79                 dataIndex: 'estimate',\r
80                 summaryType:'sum',\r
81                 renderer : function(v){\r
82                     return v +' hours';\r
83                 },\r
84                 editor: new Ext.form.NumberField({\r
85                    allowBlank: false,\r
86                    allowNegative: false,\r
87                    style: 'text-align:left'\r
88                 })\r
89             },{\r
90                 header: "Rate",\r
91                 width: 20,\r
92                 sortable: true,\r
93                 renderer: Ext.util.Format.usMoney,\r
94                 dataIndex: 'rate',\r
95                 summaryType:'average',\r
96                 editor: new Ext.form.NumberField({\r
97                     allowBlank: false,\r
98                     allowNegative: false,\r
99                     style: 'text-align:left'\r
100                 })\r
101             },{\r
102                 id: 'cost',\r
103                 header: "Cost",\r
104                 width: 20,\r
105                 sortable: false,\r
106                 groupable: false,\r
107                 renderer: function(v, params, record){\r
108                     return Ext.util.Format.usMoney(record.data.estimate * record.data.rate);\r
109                 },\r
110                 dataIndex: 'cost',\r
111                 summaryType:'totalCost',\r
112                 summaryRenderer: Ext.util.Format.usMoney\r
113             }\r
114         ],\r
115 \r
116         view: new Ext.grid.GroupingView({\r
117             forceFit:true,\r
118             showGroupName: false,\r
119             enableNoGroups:false, // REQUIRED!\r
120             hideGroupedColumn: true\r
121         }),\r
122 \r
123         plugins: summary,\r
124 \r
125         frame:true,\r
126         width: 800,\r
127         height: 450,\r
128         clicksToEdit: 1,\r
129         collapsible: true,\r
130         animCollapse: false,\r
131         trackMouseOver: false,\r
132         //enableColumnMove: false,\r
133         title: 'Sponsored Projects',\r
134         iconCls: 'icon-grid',\r
135         renderTo: document.body\r
136     });\r
137 });\r
138 \r
139 Ext.grid.dummyProjects = [\r
140     {projectId: 100, project: 'Ext Forms: Field Anchoring'},\r
141     {projectId: 101, project: 'Ext Grid: Single-level Grouping'},\r
142     {projectId: 102, project: 'Ext Grid: Summary Rows'}\r
143 ];\r
144 \r
145 Ext.grid.dummyData = [\r
146     {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
147     {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 113, description: 'Implement AnchorLayout', estimate: 4, rate: 150, due:'06/25/2007'},\r
148     {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
149     {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 115, description: 'Testing and debugging', estimate: 8, rate: 0, due:'06/29/2007'},\r
150     {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
151     {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
152     {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
153     {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 121, description: 'Default CSS Styling', estimate: 2, rate: 100, due:'07/05/2007'},\r
154     {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 104, description: 'Testing and debugging', estimate: 6, rate: 100, due:'07/06/2007'},\r
155     {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 105, description: 'Ext Grid plugin integration', estimate: 4, rate: 125, due:'07/01/2007'},\r
156     {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 106, description: 'Summary creation during rendering phase', estimate: 4, rate: 125, due:'07/02/2007'},\r
157     {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
158     {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 108, description: 'Remote summary integration', estimate: 4, rate: 125, due:'07/05/2007'},\r
159     {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 109, description: 'Summary renderers and calculators', estimate: 4, rate: 125, due:'07/06/2007'},\r
160     {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 110, description: 'Integrate summaries with GroupingView', estimate: 10, rate: 125, due:'07/11/2007'},\r
161     {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 111, description: 'Testing and debugging', estimate: 8, rate: 125, due:'07/15/2007'}\r
162 ];