数据表 - 将标题中包含多行的表导出为PDF

时间:2016-10-11 16:00:34

标签: javascript pdf datatables

基于以下table我需要将其导出为PDF文件,标题在视图中有两行但在PDF中只有一行。我不知道我是否遗漏了什么。为了在生成的文件中获得相同的表,任何想法?

HTML表:我需要在生成的PDF文件中显示标题(colspan和rowspan)。

<table id="example" class="table table-bordered table-striped">
    <!-- Two rows in the header but only one in the PDF -->
    <thead> 
        <tr>
            <th rowspan="2">Name</th>
            <th colspan="2">HR Information</th>
            <th colspan="3">Contact</th>
        </tr>
        <tr>
            <th>Position</th>
            <th>Salary</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>E-mail</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Salary</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>E-mail</th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>$320,800</td>
            <td>Edinburgh</td>
            <td>5421</td>
            <td>t.nixon@datatables.net</td>
        </tr>

            .
            .
            .

        <tr>
            <td>Donna Snider</td>
            <td>Customer Support</td>
            <td>$112,000</td>
            <td>New York</td>
            <td>4226</td>
            <td>d.snider@datatables.net</td>
        </tr>
    </tbody>
</table>

脚本

$(document).ready(function(){
        $('#example').DataTable({
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'pdfHtml5',
                    orientation: 'landscape',
                    pageSize: 'LETTER'
                },
                'print'                    
            ],

            "bLengthChange": true,
            "searching" : false,
            "info": false,
            "ordering": false,
            "paging" : true,
        })
    });

0 个答案:

没有答案