数据表在导出的pdf文件中不包含多个标题行 [英] Datatable doesn't include multiple header rows into exported pdf file

查看:129
本文介绍了数据表在导出的pdf文件中不包含多个标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的数据表HTML:

Here is my HTML for datatable:

<table id="assessment-data-datatable-{{ $assessor->user_id }}">
  <thead>
    <tr class="success">
      <th>Assessee: {{ $assignment->assessee->fullname }}</th>
      <th>Assessor: {{ $assessor->fullname }}</th>
      <th>Status: {{ $assessor->pivot->status }} </th>
    </tr>
    <tr>
      <th>Parameter</th>
      <th>Assessment</th>
      <th>Provided on</th>
    </tr>
  </thead>
</table>

这是js代码:

    var dt = $('#assessment-data-datatable-' + assessorId).DataTable({
                processing: true,
                serverSide: true,
                ajax: '/assessment/' + assessmentId + '/' + assessorId + '/fetch',
                columns: [
                { data: 'parameter', defaultContent: 'N/A' },
                { data: 'assessment_value', defaultContent: 'N/A' },
                { data: 'created_at', defaultContent: 'N/A' }
                ],
                dom: 'Bfrtip',
                buttons: [
                {
                    extend: 'pdf',
                    filename: assesseeName + ' assessment by ' +  assessorName,
                    exportoptions: {
                        header: true,
                        footer: true
                    }
                }
                ],
                destroy: true
            });

上面的代码效果很好,并且还将内容导出到pdf文件中。但是在导出的pdf文件中,仅生成了第二个标题行。 <的第一行标头>被排除。我还尝试将该行移至<

Above code works pretty well and it also exports the content into a pdf file. But into the exported pdf file, there is only second header row getting generated. Somehow the first row of the < header > gets excluded. I have also tried to move that row into < tfoot > and then export, but it also gets excluded there as well.

我认为这里的问题是datatable只允许从表头导出最多一行。

I think the issue here is that datatable only allows to export at max one row from the table header.

在这里看到它如何排除标题行:(pdf屏幕截图)

See here that how it exludes a row in header: (pdf screenshot)

任何帮助将不胜感激。

谢谢

Parth Vora

Parth Vora

推荐答案

我猜还没有将多行导出到标题的功能在数据表本身中实现。

I guess feature to export multiple rows into header is not yet implemented in datatable itself.

在此处查看数据表所有者的答案:
https://github.com/DataTables/Buttons/pull/55

See datattable owner answer here: https://github.com/DataTables/Buttons/pull/55

我发现了为什么没有

此代码:

buttons: [
  {
    extend: 'pdf',
    filename: assesseeName + ' assessment by ' +  assessorName,
    exportoptions: {
      header: true,
      footer: true
    }
  }
]

应该是这样的:

buttons: [
  {
    extend: 'pdf',
    filename: assesseeName + ' assessment by ' +  assessorName,
  },
  header: true,
  footer: true
]

页眉和页脚选项应位于外部对象上。

header and footer option should be on the outer object.

这篇关于数据表在导出的pdf文件中不包含多个标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆