hybrid-totals.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.onReady(function() {
  7. Ext.QuickTips.init();
  8. var xg = Ext.grid;
  9. var reader = new Ext.data.JsonReader({
  10. idProperty : 'taskId',
  11. root : 'data',
  12. remoteGroup : true,
  13. remoteSort : true,
  14. fields : [{
  15. name : 'projectId',
  16. type : 'int'
  17. }, {
  18. name : 'project',
  19. type : 'string'
  20. }, {
  21. name : 'taskId',
  22. type : 'int'
  23. }, {
  24. name : 'description',
  25. type : 'string'
  26. }, {
  27. name : 'estimate',
  28. type : 'float'
  29. }, {
  30. name : 'rate',
  31. type : 'float'
  32. }, {
  33. name : 'cost',
  34. type : 'float'
  35. }, {
  36. name : 'due',
  37. type : 'date',
  38. dateFormat : 'm/d/Y'
  39. }]
  40. });
  41. // define a custom summary function
  42. Ext.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field) {
  43. return v + (record.data.estimate * record.data.rate);
  44. }
  45. var summary = new Ext.grid.HybridSummary();
  46. var grid = new xg.EditorGridPanel({
  47. ds : new Ext.data.GroupingStore({
  48. reader : reader,
  49. proxy : new Ext.data.HttpProxy({
  50. url : 'summary.json',
  51. method : 'GET'
  52. }),
  53. sortInfo : {
  54. field : 'due',
  55. direction : "ASC"
  56. },
  57. groupField : 'project'
  58. }),
  59. columns : [{
  60. id : 'description',
  61. header : "Task",
  62. width : 80,
  63. sortable : true,
  64. dataIndex : 'description',
  65. summaryType : 'count',
  66. hideable : false,
  67. summaryRenderer : function(v, params, data) {
  68. return ((v === 0 || v > 1)
  69. ? '(' + v + ' Tasks)'
  70. : '(1 Task)');
  71. },
  72. editor : new Ext.form.TextField({
  73. allowBlank : false
  74. })
  75. }, {
  76. header : "Project",
  77. width : 20,
  78. sortable : true,
  79. dataIndex : 'project'
  80. }, {
  81. header : "Due Date",
  82. width : 25,
  83. sortable : true,
  84. dataIndex : 'due',
  85. summaryType : 'max',
  86. renderer : Ext.util.Format.dateRenderer('m/d/Y'),
  87. editor : new Ext.form.DateField({
  88. format : 'm/d/Y'
  89. })
  90. }, {
  91. header : "Estimate",
  92. width : 20,
  93. sortable : true,
  94. dataIndex : 'estimate',
  95. summaryType : 'sum',
  96. renderer : function(v) {
  97. return v + ' hours';
  98. },
  99. editor : new Ext.form.NumberField({
  100. allowBlank : false,
  101. allowNegative : false,
  102. style : 'text-align:left'
  103. })
  104. }, {
  105. header : "Rate",
  106. width : 20,
  107. sortable : true,
  108. renderer : Ext.util.Format.usMoney,
  109. dataIndex : 'rate',
  110. summaryType : 'average',
  111. editor : new Ext.form.NumberField({
  112. allowBlank : false,
  113. allowNegative : false,
  114. style : 'text-align:left'
  115. })
  116. }, {
  117. id : 'cost',
  118. header : "Cost",
  119. width : 20,
  120. sortable : false,
  121. groupable : false,
  122. renderer : function(v, params, record) {
  123. return Ext.util.Format.usMoney(record.data.estimate
  124. * record.data.rate);
  125. },
  126. dataIndex : 'cost',
  127. summaryType : 'totalCost',
  128. summaryRenderer : Ext.util.Format.usMoney
  129. }],
  130. view : new Ext.grid.GroupingView({
  131. forceFit : true,
  132. showGroupName : false,
  133. hideGroupedColumn : true
  134. }),
  135. plugins : summary,
  136. tbar : [{
  137. text : 'Toggle',
  138. handler : function() {
  139. summary.toggleSummaries();
  140. }
  141. }],
  142. frame : true,
  143. width : 800,
  144. height : 450,
  145. clicksToEdit : 1,
  146. collapsible : true,
  147. animCollapse : false,
  148. trackMouseOver : false,
  149. // enableColumnMove: false,
  150. title : 'Sponsored Projects',
  151. iconCls : 'icon-grid',
  152. renderTo : document.body
  153. });
  154. grid.on('afteredit', function() {
  155. var groupValue = 'Ext Forms: Field Anchoring';
  156. summary.showSummaryMsg(groupValue, 'Updating Summary...');
  157. setTimeout(function() { // simulate server call
  158. summary.updateSummaryData(groupValue, {
  159. due : new Date(2007, 6, 29),
  160. estimate : 21,
  161. rate : 185,
  162. cost : 2900
  163. });
  164. }, 2000);
  165. });
  166. grid.store.load();
  167. });
  168. Ext.grid.dummyProjects = [{
  169. projectId : 100,
  170. project : 'Ext Forms: Field Anchoring'
  171. }, {
  172. projectId : 101,
  173. project : 'Ext Grid: Single-level Grouping'
  174. }, {
  175. projectId : 102,
  176. project : 'Ext Grid: Summary Rows'
  177. }];
  178. Ext.grid.dummyData = [{
  179. projectId : 100,
  180. project : 'Ext Forms: Field Anchoring',
  181. taskId : 112,
  182. description : 'Integrate 2.0 Forms with 2.0 Layouts',
  183. estimate : 6,
  184. rate : 150,
  185. due : '06/24/2007'
  186. }, {
  187. projectId : 100,
  188. project : 'Ext Forms: Field Anchoring',
  189. taskId : 113,
  190. description : 'Implement AnchorLayout',
  191. estimate : 4,
  192. rate : 150,
  193. due : '06/25/2007'
  194. }, {
  195. projectId : 100,
  196. project : 'Ext Forms: Field Anchoring',
  197. taskId : 114,
  198. description : 'Add support for multiple types of anchors',
  199. estimate : 4,
  200. rate : 150,
  201. due : '06/27/2007'
  202. }, {
  203. projectId : 100,
  204. project : 'Ext Forms: Field Anchoring',
  205. taskId : 115,
  206. description : 'Testing and debugging',
  207. estimate : 8,
  208. rate : 0,
  209. due : '06/29/2007'
  210. }, {
  211. projectId : 101,
  212. project : 'Ext Grid: Single-level Grouping',
  213. taskId : 101,
  214. description : 'Add required rendering "hooks" to GridView',
  215. estimate : 6,
  216. rate : 100,
  217. due : '07/01/2007'
  218. }, {
  219. projectId : 101,
  220. project : 'Ext Grid: Single-level Grouping',
  221. taskId : 102,
  222. description : 'Extend GridView and override rendering functions',
  223. estimate : 6,
  224. rate : 100,
  225. due : '07/03/2007'
  226. }, {
  227. projectId : 101,
  228. project : 'Ext Grid: Single-level Grouping',
  229. taskId : 103,
  230. description : 'Extend Store with grouping functionality',
  231. estimate : 4,
  232. rate : 100,
  233. due : '07/04/2007'
  234. }, {
  235. projectId : 101,
  236. project : 'Ext Grid: Single-level Grouping',
  237. taskId : 121,
  238. description : 'Default CSS Styling',
  239. estimate : 2,
  240. rate : 100,
  241. due : '07/05/2007'
  242. }, {
  243. projectId : 101,
  244. project : 'Ext Grid: Single-level Grouping',
  245. taskId : 104,
  246. description : 'Testing and debugging',
  247. estimate : 6,
  248. rate : 100,
  249. due : '07/06/2007'
  250. }, {
  251. projectId : 102,
  252. project : 'Ext Grid: Summary Rows',
  253. taskId : 105,
  254. description : 'Ext Grid plugin integration',
  255. estimate : 4,
  256. rate : 125,
  257. due : '07/01/2007'
  258. }, {
  259. projectId : 102,
  260. project : 'Ext Grid: Summary Rows',
  261. taskId : 106,
  262. description : 'Summary creation during rendering phase',
  263. estimate : 4,
  264. rate : 125,
  265. due : '07/02/2007'
  266. }, {
  267. projectId : 102,
  268. project : 'Ext Grid: Summary Rows',
  269. taskId : 107,
  270. description : 'Dynamic summary updates in editor grids',
  271. estimate : 6,
  272. rate : 125,
  273. due : '07/05/2007'
  274. }, {
  275. projectId : 102,
  276. project : 'Ext Grid: Summary Rows',
  277. taskId : 108,
  278. description : 'Remote summary integration',
  279. estimate : 4,
  280. rate : 125,
  281. due : '07/05/2007'
  282. }, {
  283. projectId : 102,
  284. project : 'Ext Grid: Summary Rows',
  285. taskId : 109,
  286. description : 'Summary renderers and calculators',
  287. estimate : 4,
  288. rate : 125,
  289. due : '07/06/2007'
  290. }, {
  291. projectId : 102,
  292. project : 'Ext Grid: Summary Rows',
  293. taskId : 110,
  294. description : 'Integrate summaries with GroupingView',
  295. estimate : 10,
  296. rate : 125,
  297. due : '07/11/2007'
  298. }, {
  299. projectId : 102,
  300. project : 'Ext Grid: Summary Rows',
  301. taskId : 111,
  302. description : 'Testing and debugging',
  303. estimate : 8,
  304. rate : 125,
  305. due : '07/15/2007'
  306. }];