Extjs的grid總計實現

注意:前臺頁面相加計算的列,後臺傳的值必須是int、double或float(數值型)

Ext.define('person.view.tongji.Salary', {

    extend: 'Ext.panel.Panel',
    layout: 'border',
    border: false,
    margins: '0 0 0 0',
    initComponent: function() {
        var me = this;
        var store = Ext.create('Ext.data.Store', { // 定義數據源
            autoLoad: true,
            fields: ["pkid",'ksname','type1','type2','note','salary','kou'],
            pageSize : 30, // 設置分頁大小
            proxy: {
                type: 'ajax',
                url: 'kaoqin/getSalaryTongJiList.do',
                // 請求的服務器地址
                reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'totalCount'
                }
            },
            listeners: {
                load: function() {
                },
                beforeload: function(store) {
                var yuec=Ext.getCmp('tongji_salary_yuec').getValue()+"";
                var yuez=Ext.getCmp('tongji_salary_yuez').getValue()+"";
                    Ext.apply(store.proxy.extraParams,{
                        datec:Ext.getCmp('tongji_salary_nianc').getValue()+'/'+(yuec.length==1?'0'+yuec:yuec),
                        datez:Ext.getCmp('tongji_salary_nianz').getValue()+'/'+(yuez.length==1?'0'+yuez:yuez)
                    });
                }
            }
        });
        function taskInfo(value, cellmeta, record, rowIndex, columnIndex,store){
  cellmeta.tdAttr='data-qtip="'+value+'"';  //列加提示
  if(record.data.pkid==0){
  return "<span style='color:red;cursor: pointer;'>"+value+"</span>";  
  }else{
  return value;
  }
  }
        var grid = Ext.create('Ext.grid.Panel', {
            region: 'center',
            store: store,
            border: false,
            selType:'rowmodel',
            features: [{
                ftype: 'summary'
            }],

            margins: '0 0 0 0',
            enableColumnHide: false,
            columns: [Ext.create('Ext.grid.RowNumberer', {
                text: "序號",
                align: 'center',
                flex: 1,
                summaryRenderer:function(value, summaryData, dataIndex){
                return "<font color='red' size='2'>合計</font>";
                }

            }),  {
                text: "所在科室",
                flex: 2,
                align: 'center',
                sortable: true,
                renderer:taskInfo,
                dataIndex: 'ksname',
            summaryRenderer: function (value, summaryData, dataIndex) {
        return "<font color='red' size='2'>--</font>";
        }
            },{
                text: "二級人數",
                flex: 2,
                align: 'center',
                sortable: true
                ,renderer:taskInfo,
                dataIndex: 'type1',
                summaryType: 'sum',
summaryRenderer: function (value, summaryData, dataIndex) {
        return "<font color='red' size='2'>"+parseInt(value)+"</font>";
        }



            },{
                text: "三級人數",
                flex: 2,
                align: 'center',
                sortable: true,
                summaryType: 'sum',
                dataIndex: 'type2',
                renderer:taskInfo,
summaryRenderer: function (value, summaryData, dataIndex) {
        return "<font color='red' size='2'>"+parseInt(value)+"</font>";
        }
            },{
                text: "實發金額總數(元)",
                flex: 2,
                align: 'center',
                sortable: true,
                summaryType: 'sum',
                dataIndex: 'salary',
                renderer:taskInfo,
summaryRenderer: function (value, summaryData, dataIndex) {

return "<font color='red' size='2'>"+parseInt(value).toFixed(2)+"</font>";
}
            },{
                text: "扣罰金額總數(元)",
                flex: 2,
                align: 'center',
                sortable: true,
                summaryType: 'sum',
                dataIndex: 'kou',
                renderer:taskInfo,
summaryRenderer: function (value, summaryData, dataIndex) {
return "<font color='red' size='2'>"+parseInt(value).toFixed(2)+"</font>";
        }
            },{
                text: "備註",
                flex: 2,
                align: 'center',
                sortable: true,
                dataIndex: 'note',
                renderer:function(v,cellmeta){
            if(v&&v.length>15){
              cellmeta.tdAttr = 'data-qtip="'
            + v
            + '"'; // 列加提示
               }
               return v;
           },
            summaryRenderer: function (value, summaryData, dataIndex) {
        return "<font color='red' size='2'>--</font>";
        }
            }],
            columnLines: true,
            dockedItems: [{ // 工具欄
                xtype: 'toolbar',
                items: [
// '->',
{
xtype:'fieldcontainer',
layout:'hbox',
fieldLabel:'日期從',
margin:'0 5 0 5',
labelWidth:40,
items:[{
xtype : 'combo',
width:55,
store:[new Date().getFullYear()-2,new Date().getFullYear()-1,new Date().getFullYear()],
editable:false,
                   triggerAction : 'all',
queryMode : 'local',
margin : '0 5 0 5',
id:'tongji_salary_nianc',
value:new Date().getFullYear() 
},
{
xtype : 'displayfield',
value : '年'
}, {
xtype : 'combo',
width:40,
store:[1,2,3,4,5,6,7,8,9,10,11,12],
editable:false,
                   triggerAction : 'all',
queryMode : 'local',
margin : '0 5 0 5',
id:'tongji_salary_yuec',
value: new Date().getMonth()
}, {
xtype : 'displayfield',
margin : '0 5 0 5',
value : '月'
}]
},
{
xtype:'fieldcontainer',
layout:'hbox',
fieldLabel:'至',
margin:'0 5 0 5',
labelWidth:40,
items:[{
xtype : 'combo',
width:55,
store:[new Date().getFullYear()-2,new Date().getFullYear()-1,new Date().getFullYear()],
editable:false,
                   triggerAction : 'all',
queryMode : 'local',
margin : '0 5 0 5',
id:'tongji_salary_nianz',
value:new Date().getFullYear() 
},
{
xtype : 'displayfield',
value : '年'
}, {
xtype : 'combo',
width:40,
store:[1,2,3,4,5,6,7,8,9,10,11,12],
editable:false,
                   triggerAction : 'all',
queryMode : 'local',
margin : '0 5 0 5',
id:'tongji_salary_yuez',
value: new Date().getMonth()+1
}, {
xtype : 'displayfield',
margin : '0 5 0 5',
value : '月'
}]
}
,{
xtype:'button',
text : '查詢',
width:50,
margin:'0 5 0 5',
icon:'images/search.png',
handler : function() {
Ext.getCmp('tongji_salary_pagebar').moveFirst();
store.load();
}
},
{
text : '重置',
xtype:'button',
width:50,
icon:'images/cz.png',
handler : function() {
Ext.getCmp('tongji_salary_nian').setValue(new Date().getFullYear());
Ext.getCmp('tongji_salary_yue').setValue(new Date().getMonth()+1);
}
},'-',{
       text: "導出彙總表",
       tooltip: '導出獎金彙總表詳細信息',
       icon: 'images/export.png',
       handler: function() {
        var yuec=Ext.getCmp('tongji_salary_yuec').getValue()+"";
               var yuez=Ext.getCmp('tongji_salary_yuez').getValue()+"";
                   var datec=Ext.getCmp('tongji_salary_nianc').getValue()+'/'+(yuec.length==1?'0'+yuec:yuec);
                   var datez=Ext.getCmp('tongji_salary_nianz').getValue()+'/'+(yuez.length==1?'0'+yuez:yuez);
                   window.open("tongji/exportSalaryInfo.do?datec="+datec+"&datez="+datez).focus();
       }
   }]
            }],
            border: false,
           // frame: true,
            header:false,
            iconCls: 'icon-grid',
            bbar: [{ // 分頁工具條
                xtype: 'pagingtoolbar',
                id: 'tongji_salary_pagebar',
                store: store,
                // 這裏需要指定與表格相同的store
                displayInfo: true
            }]
        });
        me.items = [grid];
        me.callParent(arguments);
    }
});
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章