totals-hybrid.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:5k
源码类别:

中间件编程

开发平台:

JavaScript

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