2015-02-09 77 views
1

我在html表格上创建打印选项。 该表格有数百行。数据从php和AJAX中获取。 获取这些数据后,我将创建一个如下所示的打印选项。如何在每个页面中使用默认标题打印html表格

function PrintElem(elem){ 
    Popup($(elem).html()); 
    }// 
    function Popup(data) 
    { 
     var mywindow = window.open('', 'my div', 'width=100%'); 
     mywindow.document.write('<html><head><title></title>'); 
     mywindow.document.write('<link rel="stylesheet" href="<?php echo base_url(); ?>/resources/css/bootstrap.css" />'); 
     mywindow.document.write('</head><body >'); 
     mywindow.document.write(data); 
     mywindow.document.write('</body></html>'); 

     mywindow.document.close(); mywindow.focus(); //newwindow.focus(); 
     mywindow.print(); mywindow.close(); 
     return true; 
    }// 
<span class="trial_balance_ajax" id="print_section"> 
<!---- Ajax table data loads here-----> 
</span> 

现在我试图在打印文档的每个页面中打印表格标题列。 但在这种情况下,数据头只显示第一页,然后在其他页面数据溢出...

我想在每个页面默认的列标题

请帮助

+0

你真的不应该使用'document.write' – meskobalazs 2015-02-09 13:25:10

回答

-1

为什么不您划分行,以便您可以创建其中包含标题的另一个表。

+0

不,我想在一个页面中显示这个报告,然后有一个打印选项..所以我不能在我的查看页面做这个。 – Brett 2015-02-09 12:59:01

0

你生成的表是什么样的?我的测试表明,如果你创建一个明确的 <thead><tbody>头一个表,你会自动设置:

<table> 
    <thead> 
     <tr> 
      <th>Foo</th> 
      <th>Bar</th> 
      <th>Baz</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>!!!</td> 
      <td>!!!</td> 
      <td>!!!</td> 
     </tr> 
     <!-- Many rows... --> 
     <tr> 
      <td>!!!</td> 
      <td>!!!</td> 
      <td>!!!</td> 
     </tr> 
    </tbody> 
</table> 

换句话说,上面似乎要求工作。

编辑:所要求的行为似乎自动发生在Firefox中,但是在其他浏览器中无法实现妥协是不可能的。有关建议请参见this相关问题。

+0

是的,我的桌子和上面一样,但是没有出现每个页面的默认标题。 – Brett 2015-02-09 13:06:31

+0

对不起。看来,Firefox自动执行此操作。我会试着找到一个跨浏览器的解决方案。 – rusmus 2015-02-09 13:07:58

相关问题