php - 如何在新的分页符中重复表头

标签 php html css google-chrome

我的网页中有一个动态表,有时包含很多行。我在 22 行后进行了分页。我需要在新页面中重复某些表(信息表,见图片)。我怎么做?

图像 https://i.ibb.co/LN8gVbD/Screen-Shot-2019-05-26-at-03-34-26.png

另一件事,我无法在 Chrome 中实现分页。它只适用于 Firefox,如何在 Chrome 中修复它?

 <style type="text/css">
    #receipt-data { font-size: 12px; }
        @media print {
                tr.page-break{
                page-break-inside: avoid;;
                page-break-before:always; 
            }  
            @page {
              size:portrait;
                }
        }
    </style>

    <div id="receipt-data">
<table class="table hed">
<thead style="text-align:center;">
<tr style="text-align:center;">  
    <th colspan="1">Name</th>
<th colspan="2">{{$customer_data->name}}i</th>
<th colspan="1">Customer Tax No</th>
<th colspan="2">{{$customer_data->tax_no}}</th>
</tr>
</thead>
</table>

 <table class="table table-bordered" style="text-align:center;">
            <thead>
                <tr>
                    <th>S</th>
                    <th>Item Code</th>
                    <th>Description</th>
                    <th>Unit</th>
                    <th>Unit Price</th>
                    <th>Qty</th>
                    <th>Amount($)
                    </th>
                </tr>
            </thead>
            <tbody>

                @foreach($product_sale_data as $key=>$product_sale_data)
                @php
          $product_data = \App\Product::find($product_sale_data->product_id);
                    if($product_data->sale_unit_id)
      $unit = \App\Unit::find($product_data->sale_unit_id)->unit_name;
                    else
                        $unit = 'N/A';
                @endphp  
    <tr class =  @if  ( $key % 22 == 0 && $key ) "page-break"   @endif>
 <td>{{$key+1}}</td>
  <td>{{$product_data->code}}</td>
  <td>{{$product_data->name}}</td>
 <td>{{$unit}}</td>
<td>{{number_format($product_sale_data->total / $product_sale_data->qty, 2)}}</td>
                    <td>{{$product_sale_data->qty}}</td>
                    <td>{{number_format($product_sale_data->total, 2)}}</td>
                @endforeach
                 <br>

最佳答案

注意:如果 $key值以 0 开头然后低于 <thead>不需要,但如果$key以 1 开头然后下面需要一次不需要循环 foreach

    <thead>
        <tr>
            <th>S</th>
            <th>Item Code</th>
            <th>Description</th>
            <th>Unit</th>
            <th>Unit Price</th>
            <th>Qty</th>
            <th>Amount($)
            </th>
        </tr>
    </thead>
    @foreach($product_sale_data as $key=>$product_sale_data)
        @if  ( $key % 22 == 0 && $key ) // so here every 22 rows after this will go
            <thead>
                <tr>
                    <th>S</th>
                    <th>Item Code</th>
                    <th>Description</th>
                    <th>Unit</th>
                    <th>Unit Price</th>
                    <th>Qty</th>
                    <th>Amount($)
                    </th>
                </tr>
            </thead>
        @endif
        <tbody> 
            @php
            $product_data = \App\Product::find($product_sale_data->product_id);
                if($product_data->sale_unit_id)

            ...continue your code

关于php - 如何在新的分页符中重复表头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56310293/

相关文章:

javascript - JQuery 改进 animation() 性能

php - 使用 PHP 删除日期

php - 使用 FPDF 在单元格中自动换行?

php - Elasticsearch查询的结果(PHP)

html - Firefox 书签面板改变响应式 css 网格设计

javascript - 使用 JS 或 jquery 防止多次点击链接

PHP查询总是失败

jquery - 如何在鼠标悬停并单击时向照片添加字幕叠加层?

html - Bootstrap 3 - 在每个网格列之后打印布局和中断

javascript - 如何在列表 css 类之间进行选择