【问题标题】:page number not working in datatable export to pdf页码在数据表导出到 pdf 时不起作用
【发布时间】:2021-11-11 06:29:27
【问题描述】:

我正在尝试在 datatble pdf 导出中添加页码,在添加此代码 pdf 按钮消失并得到“未捕获的 ReferenceError: doc is not defined”后,我从其官方网站获取了代码 在 HTMLDocument' 控制台中出现错误。

$('#table2').DataTable({
    
    dom: 'Bfrtip',
   
    buttons: [
         
        {
            extend: 'pdfHtml5',
            title: 'Data export',
            filename: 'dt_custom_pdf',
            pageSize: 'A4',
                exportOptions: {
                    columns: ':visible',
                    search: 'applied',
                    order: 'applied'
                },
           
            
        },
       doc['footer']=(function(page, pages) {
        return {
        columns: [
        'Left part of footer',
            {
                alignment: 'right',
                text: [
                    { text: page.toString(), italics: true },
                    ' of ',
                    { text: pages.toString(), italics: true }
                ]
            }
        ],
        margin: [10, 0]
        }
        });
    ]
   });

【问题讨论】:

    标签: javascript jquery datatable


    【解决方案1】:

    您没有为 dataTable 定义自定义函数,为什么需要更改文档错误

    $('#table2').DataTable({
        
        dom: 'Bfrtip',
       
        buttons: [
             
            
            {
            extend: 'pdfHtml5',
            text: 'Pdf',
            filename: 'dt_custom_pdf',
            pageSize: 'A4',
                exportOptions: {
                    columns: ':visible',
                    search: 'applied',
                    order: 'applied'
                },
            customize: function ( doc ) {
                doc['footer']=(function(page, pages) {
                    return {
                    columns: [
                    
                    {
                    alignment: 'center',
                    text: [
                    { text: page.toString(), italics: true },
                    ' of ',
                    { text: pages.toString(), italics: true }
                    ]
                    }
                    ],
                    margin: [10, 0]
                    }
                    });
                
            }
        }
        
        ]
       });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多