group-summary-grid.js 7.1 KB

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