1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication1.WebForm4" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xmlns="http://www.w3.org/1999/xhtml" > 6 <head runat="server"> 7 <title></title> 8 <link href="ExtJs4.1要导入胡文件/resources/css/ext-all.css" rel="stylesheet" type="text/css" /> 9 10 <link href="ExtJs4.1要导入胡文件/shared/example.css" rel="stylesheet" type="text/css" /> 11 12 <script src="ExtJs4.1要导入胡文件/ext-all.js" type="text/javascript"></script> 13 <style type="text/css"> 14 .x-grid-group-title 15 { 16 display:none; 17 } 18 .x-grid-group-hd 19 { 20 display:none; 21 } 22 .task .x-grid-cell-inner { 23 padding-left: 15px; 24 25 } 26 .x-grid-row-summary .x-grid-cell-inner { 27 font-weight: bold; 28 font-size: 11px; 29 } 30 .icon-grid { 31 background: url(../shared/icons/fam/grid.png) no-repeat 0 -1px; 32 } 33 34 35 </style> 36 <script type="text/javascript"> 37 Ext.Loader.setConfig({ enabled: true }); 38 Ext.require([ 39 'Ext.grid.*', 40 'Ext.data.*' 41 ]); 42 var div; 43 44 Ext.define('Task', { 45 extend: 'Ext.data.Model', 46 idProperty: 'taskId', 47 fields: [ 48 {name: 'projectId', type: 'int'}, 49 {name: 'project', type: 'string'}, 50 {name: 'taskId', type: 'int'}, 51 {name: 'description', type: 'string'}, 52 {name: 'estHours', type: 'float'}, 53 {name: 'rate', type: 'float'}, 54 {name: 'cost', type: 'float'}, 55 {name: 'due', type: 'date', dateFormat:'m/d/Y'} 56 ] 57 }); 58 var myData=[ 59 { projectId: 100, project: '边学玲', taskId: 112, description: '泉北人和便利', estHours: 6, rate: 150, due: '06/24/2007',cost:'222' }, 60 { projectId: 100, project: '边学玲', taskId: 113, description: '日杂烟酒', estHours: 4, rate: 150, due: '06/25/2007', cost: '222' }, 61 { projectId: 100, project: '边学玲', taskId: 114, description: '顺福百货', estHours: 4, rate: 150, due: '06/27/2007', cost: '222' }, 62 { projectId: 100, project: '边学玲', taskId: 115, description: '步步升超市', estHours: 8, rate: 0, due: '06/29/2007', cost: '222' }, 63 { projectId: 101, project: '刘杰', taskId: 101, description: '肉厂平价超市', estHours: 6, rate: 100, due: '07/01/2007', cost: '222' }, 64 { projectId: 101, project: '刘杰', taskId: 102, description: '三喜超市', estHours: 6, rate: 100, due: '07/03/2007', cost: '222' }, 65 { projectId: 101, project: '刘杰', taskId: 103, description: '上海华联', estHours: 4, rate: 100, due: '07/04/2007', cost: '222' }, 66 { projectId: 101, project: '刘杰', taskId: 121, description: '7 Seven', estHours: 2, rate: 100, due: '07/05/2007', cost: '222' }, 67 { projectId: 101, project: '刘杰', taskId: 104, description: '家乐福', estHours: 6, rate: 100, due: '07/06/2007', cost: '222' }, 68 69 { projectId: 102, project: '崔永源', taskId: 105, description: '红太阳超市', estHours: 4, rate: 125, due: '07/01/2007', cost: '222' }, 70 { projectId: 102, project: '崔永源', taskId: 106, description: '河东烟酒', estHours: 4, rate: 125, due: '07/02/2007', cost: '222' }, 71 { projectId: 102, project: '崔永源', taskId: 107, description: '老伴便利', estHours: 6, rate: 125, due: '07/05/2007', cost: '222' }, 72 { projectId: 102, project: '崔永源', taskId: 108, description: '家家乐批发', estHours: 4, rate: 125, due: '07/05/2007', cost: '222' }, 73 { projectId: 102, project: '崔永源', taskId: 109, description: '喜来福杂货店', estHours: 4, rate: 125, due: '07/06/2007', cost: '222' }, 74 { projectId: 102, project: '崔永源', taskId: 110, description: '又一村卖场', estHours: 10, rate: 125, due: '07/11/2007', cost: '222' } 75 ]; 76 Ext.onReady(function() { 77 78 function gridSum(grid) { 79 80 var sum = 0; //时间总计 81 var sum1 = 0; //价格总计 82 var sum2 = 0; //消费总计 83 grid.store.each(function(record) { 84 85 sum += Number(record.data.estHours); 86 sum1 += Number((record.data.rate)); 87 sum2 += Number(record.data.cost); 88 }); 89 sum1 = sum1 / (grid.getStore().getCount()); 90 var data = [ 91 { projectId: 100, project: '边学玲', taskId: 112, description: '泉北人和便利', estHours: 6, rate: 150, due: '06/24/2007', cost: '222' }, 92 { projectId: 100, project: '边学玲', taskId: 113, description: '日杂烟酒', estHours: 4, rate: 150, due: '06/25/2007', cost: '222' }, 93 { projectId: 100, project: '边学玲', taskId: 114, description: '顺福百货', estHours: 4, rate: 150, due: '06/27/2007', cost: '222' }, 94 { projectId: 100, project: '边学玲', taskId: 115, description: '步步升超市', estHours: 8, rate: 0, due: '06/29/2007', cost: '222' }, 95 { projectId: 101, project: '刘杰', taskId: 101, description: '肉厂平价超市', estHours: 6, rate: 100, due: '07/01/2007', cost: '222' }, 96 { projectId: 101, project: '刘杰', taskId: 102, description: '三喜超市', estHours: 6, rate: 100, due: '07/03/2007', cost: '222' }, 97 { projectId: 101, project: '刘杰', taskId: 103, description: '上海华联', estHours: 4, rate: 100, due: '07/04/2007', cost: '222' }, 98 { projectId: 101, project: '刘杰', taskId: 121, description: '7 Seven', estHours: 2, rate: 100, due: '07/05/2007', cost: '222' }, 99 { projectId: 101, project: '刘杰', taskId: 104, description: '家乐福', estHours: 6, rate: 100, due: '07/06/2007', cost: '222' }, 100 { projectId: 102, project: '崔永源', taskId: 105, description: '红太阳超市', estHours: 4, rate: 125, due: '07/01/2007', cost: '222' }, 101 { projectId: 102, project: '崔永源', taskId: 106, description: '河东烟酒', estHours: 4, rate: 125, due: '07/02/2007', cost: '222' }, 102 { projectId: 102, project: '崔永源', taskId: 107, description: '老伴便利', estHours: 6, rate: 125, due: '07/05/2007', cost: '222' }, 103 { projectId: 102, project: '崔永源', taskId: 108, description: '家家乐批发', estHours: 4, rate: 125, due: '07/05/2007', cost: '222' }, 104 { projectId: 102, project: '崔永源', taskId: 109, description: '喜来福杂货店', estHours: 4, rate: 125, due: '07/06/2007', cost: '222' }, 105 { projectId: 102, project: '崔永源', taskId: 110, description: '又一村卖场', estHours: 10, rate: 125, due: '07/11/2007', cost: '222' }, 106 { 107 108 description: '总计', 109 estHours: sum, 110 rate: sum1, 111 due: '07/15/2007', 112 cost: sum2 113 }]; 114 115 grid.store.loadData(data, false); 116 } 117 118 var store = Ext.create("Ext.data.Store", { 119 model: 'Task', 120 remoteGroup: true, 121 data: myData, 122 groupField: 'project' 123 }); 124 125 var grid = Ext.create('Ext.grid.Panel', { 126 width: 800, 127 height: 450, 128 remoteGroup: true, 129 title: 'Data Total', 130 renderTo: Ext.getBody(), 131 store: store, 132 stripeRow: false, 133 134 features: [{ 135 id: 'group', 136 ftype: 'groupingsummary', 137 138 hideGroupedHeader: true, 139 remoteRoot: 'summaryData', 140 enableGroupingMenu: false 141 }], 142 columns: [{ 143 text: '终端名称', 144 flex: 1, 145 tdCls: 'task', 146 dataIndex: 'description', 147 summaryType: 'count', 148 summaryRenderer: function(value, summaryData, dataIndex) { 149 //return ((value === 0 || value > 1) ? '(' + value + ' Tasks)' : '(1 Task)'); 150 return ((value === 0 || value > 1) ? '(小计)' : '(总计)'); 151 //return '()'; 152 } 153 }, { 154 header: '日期', 155 width: 120, 156 dataIndex: 'due', 157 renderer: Ext.util.Format.dateRenderer('Y-m-d') 158 }, { 159 header: '时间', 160 width: 100, 161 dataIndex: 'estHours', 162 summaryType: 'sum', 163 renderer: function(value, metaData, record, rowIdx, colIdx, store, view) { 164 return value + 'hours'; 165 }, 166 summaryRenderer: function(value, summaryData, dataIndex) { 167 return value + 'hours'; 168 } 169 }, { 170 header: '平均价格', 171 width: 75, 172 renderer: Ext.util.Format.usMoney, 173 summaryRenderer: Ext.util.Format.usMoney, 174 dataIndex: 'rate', 175 summaryType: 'average' 176 }, { 177 header: '消费', 178 width: 100, 179 renderer: Ext.util.Format.usMoney, 180 dataIndex: 'cost', 181 summaryRenderer: Ext.util.Format.usMoney, 182 summaryType: 'sum' 183 }, { 184 header:'合计', 185 width: 100, 186 groupable: false, 187 summaryType:'sum', 188 summaryRenderer: Ext.util.Format.usMoney, 189 renderer: function(value, metaData, record, rowIdx, colIdx, store, view) { 190 return Ext.util.Format.usMoney(record.get('estHours') * record.get('rate')); 191 } 192 } 193 ] 194 }); 195 196 gridSum(grid); 197 198 document.getElementById("gridview-1017-bd-").style.display = "none"; 199 200 201 202 203 204 }); 205 206 </script> 207 208 </head> 209 <body> 210 211 </body> 212 </html>
问题1:把总计放到最后一行显示
2:只显示最后一个总计
3:为什么小计后面的数据没计算