locking-grp-summary-grp-hdrs-grid.js 7.6 KB

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