You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
7.6 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function(){
  16. Ext.QuickTips.init();
  17. var xg = Ext.grid;
  18. var reader = new Ext.data.JsonReader({
  19. idProperty: 'taskId',
  20. fields: [
  21. {name: 'projectId', type: 'int'},
  22. {name: 'project', type: 'string'},
  23. {name: 'taskId', type: 'int'},
  24. {name: 'description', type: 'string'},
  25. {name: 'estimate', type: 'float'},
  26. {name: 'rate', type: 'float'},
  27. {name: 'cost', type: 'float'},
  28. {name: 'due', type: 'date', dateFormat:'m/d/Y'}
  29. ]
  30. });
  31. // define a custom summary function
  32. Ext.ux.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
  33. return v + (record.data.estimate * record.data.rate);
  34. };
  35. // utilize custom extension for Group Summary
  36. var summary = new Ext.ux.grid.GroupSummary();
  37. var grid = new xg.EditorGridPanel({
  38. ds: new Ext.data.GroupingStore({
  39. reader: reader,
  40. // use local data
  41. data: app.grid.dummyData,
  42. sortInfo: {field: 'due', direction: 'ASC'},
  43. groupField: 'project'
  44. }),
  45. columns: [
  46. {
  47. id: 'description',
  48. header: 'Task',
  49. width: 80,
  50. sortable: true,
  51. dataIndex: 'description',
  52. summaryType: 'count',
  53. hideable: false,
  54. summaryRenderer: function(v, params, data){
  55. return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');
  56. },
  57. editor: new Ext.form.TextField({
  58. allowBlank: false
  59. })
  60. },{
  61. header: 'Project',
  62. width: 20,
  63. sortable: true,
  64. dataIndex: 'project'
  65. },{
  66. header: 'Due Date',
  67. width: 25,
  68. sortable: true,
  69. dataIndex: 'due',
  70. summaryType: 'max',
  71. renderer: Ext.util.Format.dateRenderer('m/d/Y'),
  72. editor: new Ext.form.DateField({
  73. format: 'm/d/Y'
  74. })
  75. },{
  76. header: 'Estimate',
  77. width: 20,
  78. sortable: true,
  79. dataIndex: 'estimate',
  80. summaryType: 'sum',
  81. renderer : function(v){
  82. return v +' hours';
  83. },
  84. editor: new Ext.form.NumberField({
  85. allowBlank: false,
  86. allowNegative: false,
  87. style: 'text-align:left'
  88. })
  89. },{
  90. header: 'Rate',
  91. width: 20,
  92. sortable: true,
  93. renderer: Ext.util.Format.usMoney,
  94. dataIndex: 'rate',
  95. summaryType: 'average',
  96. editor: new Ext.form.NumberField({
  97. allowBlank: false,
  98. allowNegative: false,
  99. style: 'text-align:left'
  100. })
  101. },{
  102. id: 'cost',
  103. header: 'Cost',
  104. width: 20,
  105. sortable: false,
  106. groupable: false,
  107. renderer: function(v, params, record){
  108. return Ext.util.Format.usMoney(record.data.estimate * record.data.rate);
  109. },
  110. dataIndex: 'cost',
  111. summaryType: 'totalCost',
  112. summaryRenderer: Ext.util.Format.usMoney
  113. }
  114. ],
  115. view: new Ext.grid.GroupingView({
  116. forceFit: true,
  117. showGroupName: false,
  118. enableNoGroups: false,
  119. enableGroupingMenu: false,
  120. hideGroupedColumn: true
  121. }),
  122. plugins: summary,
  123. tbar : [{
  124. text: 'Toggle',
  125. tooltip: 'Toggle the visibility of summary row',
  126. handler: function(){summary.toggleSummaries();}
  127. }],
  128. frame: true,
  129. width: 800,
  130. height: 450,
  131. clicksToEdit: 1,
  132. collapsible: true,
  133. animCollapse: false,
  134. trackMouseOver: false,
  135. //enableColumnMove: false,
  136. title: 'Sponsored Projects',
  137. iconCls: 'icon-grid',
  138. renderTo: document.body
  139. });
  140. });
  141. // set up namespace for application
  142. Ext.ns('app.grid');
  143. // store dummy data in the app namespace
  144. app.grid.dummyData = [
  145. {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'},
  146. {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 113, description: 'Implement AnchorLayout', estimate: 4, rate: 150, due:'06/25/2007'},
  147. {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'},
  148. {projectId: 100, project: 'Ext Forms: Field Anchoring', taskId: 115, description: 'Testing and debugging', estimate: 8, rate: 0, due:'06/29/2007'},
  149. {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'},
  150. {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'},
  151. {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 103, description: 'Extend Store with grouping functionality', estimate: 4, rate: 100, due:'07/04/2007'},
  152. {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 121, description: 'Default CSS Styling', estimate: 2, rate: 100, due:'07/05/2007'},
  153. {projectId: 101, project: 'Ext Grid: Single-level Grouping', taskId: 104, description: 'Testing and debugging', estimate: 6, rate: 100, due:'07/06/2007'},
  154. {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 105, description: 'Ext Grid plugin integration', estimate: 4, rate: 125, due:'07/01/2007'},
  155. {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 106, description: 'Summary creation during rendering phase', estimate: 4, rate: 125, due:'07/02/2007'},
  156. {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 107, description: 'Dynamic summary updates in editor grids', estimate: 6, rate: 125, due:'07/05/2007'},
  157. {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 108, description: 'Remote summary integration', estimate: 4, rate: 125, due:'07/05/2007'},
  158. {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 109, description: 'Summary renderers and calculators', estimate: 4, rate: 125, due:'07/06/2007'},
  159. {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 110, description: 'Integrate summaries with GroupingView', estimate: 10, rate: 125, due:'07/11/2007'},
  160. {projectId: 102, project: 'Ext Grid: Summary Rows', taskId: 111, description: 'Testing and debugging', estimate: 8, rate: 125, due:'07/15/2007'}
  161. ];