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
5.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. // additional configuration for remote
  31. root:'data',
  32. remoteGroup:true,
  33. remoteSort: true
  34. });
  35. // define a custom summary function
  36. Ext.ux.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
  37. return v + (record.data.estimate * record.data.rate);
  38. };
  39. // utilize custom extension for Hybrid Summary
  40. var summary = new Ext.ux.grid.HybridSummary();
  41. var grid = new xg.EditorGridPanel({
  42. ds: new Ext.data.GroupingStore({
  43. reader: reader,
  44. // use remote data
  45. proxy : new Ext.data.HttpProxy({
  46. url: 'totals-hybrid.json',
  47. method: 'GET'
  48. }),
  49. sortInfo: {field: 'due', direction: 'ASC'},
  50. groupField: 'project'
  51. }),
  52. columns: [
  53. {
  54. id: 'description',
  55. header: 'Task',
  56. width: 80,
  57. sortable: true,
  58. dataIndex: 'description',
  59. summaryType: 'count',
  60. hideable: false,
  61. summaryRenderer: function(v, params, data){
  62. return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');
  63. },
  64. editor: new Ext.form.TextField({
  65. allowBlank: false
  66. })
  67. },{
  68. header: 'Project',
  69. width: 20,
  70. sortable: true,
  71. dataIndex: 'project'
  72. },{
  73. header: 'Due Date',
  74. width: 25,
  75. sortable: true,
  76. dataIndex: 'due',
  77. summaryType:'max',
  78. renderer: Ext.util.Format.dateRenderer('m/d/Y'),
  79. editor: new Ext.form.DateField({
  80. format: 'm/d/Y'
  81. })
  82. },{
  83. header: 'Estimate',
  84. width: 20,
  85. sortable: true,
  86. dataIndex: 'estimate',
  87. summaryType:'sum',
  88. renderer : function(v){
  89. return v +' hours';
  90. },
  91. editor: new Ext.form.NumberField({
  92. allowBlank: false,
  93. allowNegative: false,
  94. style: 'text-align:left'
  95. })
  96. },{
  97. header: 'Rate',
  98. width: 20,
  99. sortable: true,
  100. renderer: Ext.util.Format.usMoney,
  101. dataIndex: 'rate',
  102. summaryType:'average',
  103. editor: new Ext.form.NumberField({
  104. allowBlank: false,
  105. allowNegative: false,
  106. style: 'text-align:left'
  107. })
  108. },{
  109. id: 'cost',
  110. header: 'Cost',
  111. width: 20,
  112. sortable: false,
  113. groupable: false,
  114. renderer: function(v, params, record){
  115. return Ext.util.Format.usMoney(record.data.estimate * record.data.rate);
  116. },
  117. dataIndex: 'cost',
  118. summaryType: 'totalCost',
  119. summaryRenderer: Ext.util.Format.usMoney
  120. }
  121. ],
  122. view: new Ext.grid.GroupingView({
  123. forceFit:true,
  124. showGroupName: false,
  125. enableNoGroups:false,
  126. enableGroupingMenu:false,
  127. hideGroupedColumn: true
  128. }),
  129. plugins: summary,
  130. tbar : [{
  131. text: 'Toggle',
  132. tooltip: 'Toggle the visibility of summary row',
  133. handler: function(){summary.toggleSummaries();}
  134. }],
  135. frame: true,
  136. width: 800,
  137. height: 450,
  138. clicksToEdit: 1,
  139. collapsible: true,
  140. animCollapse: false,
  141. trackMouseOver: false,
  142. //enableColumnMove: false,
  143. title: 'Sponsored Projects',
  144. iconCls: 'icon-grid',
  145. renderTo: document.body
  146. });
  147. grid.on('afteredit', function(){
  148. var groupValue = 'Ext Forms: Field Anchoring';
  149. summary.showSummaryMsg(groupValue, 'Updating Summary...');
  150. setTimeout(function(){ // simulate server call
  151. // HybridSummary class implements updateSummaryData
  152. summary.updateSummaryData(groupValue,
  153. // create data object based on configured dataIndex
  154. {description: 22, estimate: 888, rate: 888, due: new Date(), cost: 8});
  155. }, 2000);
  156. });
  157. // load the remote data
  158. grid.store.load();
  159. });