Extjs控件之 grid打印功能

View Code 
 var record;
 function viewScore(){
     var selections=Ext.getCmp('projectGrid').getSelectionModel().getSelections();
     if(selections.length>0){
         record=selections[0];
         var viewScoreWin=Ext.getCmp('viewScoreWin');
         if(!viewScoreWin){
             viewScoreWin = new Ext.Window({
                 id: 'viewScoreWin',
                 title: '查看项目评分',
                 width: 1000,
                 height: 350,
                 closable: true,
                 layout: 'fit',
                 closeAction: 'close',
                 plain: true,
                 modal: true,
                 iconCls: 'vcard_update',
                 bodyStyle: 'padding:5px;',
                 buttonAlign: 'center',
                 buttons: [{
                     text: '刷新',
                     handler: function() {
                         getProjectScoreStore(record.data.Id).reload();
                     }
                 },
                 {
                     text:'打印',
                     handler:printGrid
                 }
                 ],
                     items: {
                         xtype: 'panel',
                         border: false,
                         frame: false,
                         baseCls: 'x-plain',
                         items: [{
                             xtype: 'box',
                             autoEl: {
                                 tag: 'div',
                                 height: 20,
                                 id: 'averageScore' + record.data.Id,
                                 html: '平均价: ' + round2(getProjectScoreStore(record.data.Id).averageScore, 4),
                                 style: 'text-align:center;font-size:16px;font-weight:bold;line-height:20px;'
                             }
                         }, {
                             xtype: 'grid',
                             height: 250,
                             border: false,
                             viewConfig: { forceFit: true },
                             autoFill: true,
                             id: 'projectScoreGrid',
                             viewConfig:{forceFit:true},
                             store: getProjectScoreStore(record.data.Id),
                             cm: new Ext.grid.ColumnModel({
                                 columns: [
                                 new Ext.grid.RowNumberer(),
                                 { header: '专家', dataIndex: 'UserName' },
                                 {
                                     header: '评分',
                                     dataIndex: 'Score',
                                     renderer: function(v) {
                                         if (v) {
                                             return round2(v, 4)
                                         } else {
                                             return ''
                                         }
                                     }
                                 },
                                 { header: '日期', dataIndex: 'Date', renderer: Ext.util.Format.dateRenderer('Y-n-j') },
                                 { header: '土地级别', dataIndex: 'LandLevel' },
                                 { header: '土地用途', dataIndex: 'LandUse' },
                                 { header: '区段地价', dataIndex: 'DistrictLandPrice' },
                                 { header: '用途修正', dataIndex: 'UseAmend' },
                                 { header: '期日修正', dataIndex: 'DateAmend' },
                                 { header: '容积率修正', dataIndex: 'PlotRatioAmend' },
                                 { header: '年期修正', dataIndex: 'YearAmend' },
                                 { header: '个别因素修正', dataIndex: 'SingleAmend' },
                                 
                                 { header: '开发程度修正', dataIndex: 'DeveloperLevelAmend'}
                             ]
                             }),
                             sm: new Ext.grid.RowSelectionModel({ singleSelect: true })
                         }]
                         }
                     });
         }
         viewScoreWin.show();
     }else{
         Ext.MessageBox.alert('提示','请选择一个要查看的项目');
     }
 }
 function printGrid() {
     var gridcontrol = Ext.getCmp('projectScoreGrid');
     var tableStr = '<table  style="border:1 black solid; width:100%;"cellpadding=0 cellspacing=0><tr><td colspan=12 align=center style="border:1px black solid;">';
     var cm = gridcontrol.getColumnModel();
     var colCount = cm.getColumnCount();
     var temp_obj = new Array();
     for (var i = 1; i < colCount; i++) {
         if (cm.isHidden(i) ==
          true) {
 
         }
         else {
             temp_obj.push(i);
         }
     }
     tableStr = tableStr + '平均价:' + round2(getProjectScoreStore(record.data.Id).averageScore, 4)+'</td><tr>';
     for (var i = 0; i < temp_obj.length; i++) {
         tableStr = tableStr + '<td style="border:1 black solid;">' + cm.getColumnHeader(temp_obj[i]) + '</td>';
     }
     tableStr = tableStr + '</tr>';
     var store = gridcontrol.getStore();
     var recordCount = store.getCount();
     for (var i = 0; i < recordCount; i++) {
         var r = store.getAt(i);
         for (var j = 0; j < temp_obj.length; j++) {
             var dateIndex = cm.getDataIndex(temp_obj[j]);
             var tdvalue = r.get(dateIndex);
             var renderFunc = cm.getRenderer(temp_obj[j]);
             if (renderFunc != null) {
                 tdvalue = renderFunc(tdvalue);
             }
             if (tdvalue == null) {
                 tdvalue = '';
             }
             tableStr = tableStr + '<td style="border:1 black solid;">' + tdvalue + '</td>';
         }
         tableStr = tableStr + '</tr>';
     }
     tableStr = tableStr + '</table>';
     var titleHtml = tableStr;
     var newwin = window.open('printer.html', '', '');
     newwin.document.write(titleHtml);
     newwin.document.location.reload();
     newwin.print();
     newwin.close();
     
 }

知识共享许可协议
《Extjs控件之 grid打印功能》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
相邻依据:发表时间
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     162.14ms