如何打印自定义网格应用程序?

时间:2013-03-31 14:01:45

标签: rally

我在自定义应用程序中添加了打印按钮和PrintDialog,现在需要编写打印功能。 我是否需要打开一个新窗口并构建一个包含格式为css样式的网格数据的表格,该样式适合A4纸张尺寸,或者我可以使用Rally内置的东西吗? 我是Rally和Ext JS的新手,所以任何建议都会受到赞赏!

Ext.create('Rally.ui.dialog.PrintDialog', {
          height: 250,
          autoShow: true,
          autoCenter: false,
          shouldShowFormatOptions: false,
          defaultTitle: 'Book Of Work Report',
          listeners: {
                print: function(event) {
                //How do I print a grid?         
            },

2 个答案:

答案 0 :(得分:1)

为了打印网格,我创建了一个Rally.data.WsapiDataStore并将存储加载到一个数组中。我将此数组(StoreData)传递给下面的函数,该函数打开一个打印窗口,在表格中显示网格。

_printDetails: function(Storedata) {

        var myData = Storedata;    
        var htmlTable ='<table>';
        htmlTable +='<width="100%">';   

    var r,c;                   
        for(r= 0 ; r<myData.length; r++){   
            htmlTable+= '<tr>';
            for(c = 0 ; c<myData[0].length; c++){    
                htmlTable+='<td>'+myData[r][c]+'</td>';         
            }
            htmlTable+='</tr>';
        }
        htmlTable+='</table>'; 

       var cssTable = '<style type="text/css">';
        cssTable +='table {border-collapse:collapse;...}';
        cssTable +='th {color:#080808;border-bottom-style: solid; ...}';
        cssTable +='tr {color:#000000; border-bottom-style: solid; ..}';
        cssTable +='td {padding:3px 4px; text-align:left; vertical-align:top;}';
        cssTable +='#filter {text-align:left; ...}';    
        cssTable += '</style>';

        var printwindow=window.open('', '', 'width=1000,height=500');
        var myDate = new Date;
        printwindow.document.write('<div id="todayDate">' + Ext.Date.format(myDate,'F j, Y, g:i a') + '</div>');            
        printwindow.document.write('<div id="header">Book Of Work Report</div>');
        printwindow.document.write('<div id="filter"><p>' + this._GetFilterString() + '</p></div>');
        printwindow.document.write(htmlTable);
        printwindow.document.write(cssTable);   
        printwindow.document.close();
        printwindow.focus();
        printwindow.print();
        printwindow.close();
    },

答案 1 :(得分:0)

您的倾向是正确的 - 这里最好的选择是打开一个窗口,用表格输出/网格内容填充并应用您喜欢的任何CSS格式。 Rally没有任何服务器端打印输出功能(至少暴露给AppSDK2)。