代码之家  ›  专栏  ›  技术社区  ›  mfg

分页不显示在datatable中

  •  0
  • mfg  · 技术社区  · 7 年前

    有一个数据表,带有导出为PDF或Excel和打印按钮。但分页并没有出现。当我看过这些例子时,大多数都和我的项目一样;当他们按下按钮时,不会出现分页。我怎样才能解决这个问题? 数据表的js代码如下;

        var oTable = $('#datatables').dataTable({
                    destroy: true,
                    "bSort": false,
                    dom: 'Bfrtip',
                    buttons: [
                    {
                        extend: 'excelHtml5',
                        footer: true ,
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4,5,6,7]
                        }   
                    },
                    {
                        extend: 'pdfHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5]
                        },
                        customize: function (doc) {
                        //Remove the title created by datatTables
                        doc.content.splice(0, 1);
                        //Create a date string that we use in the footer. Format is dd-mm-yyyy
                        var now = new Date();
                        var jsDate = now.getDate() + '-' + (now.getMonth() + 1) + '-' + now.getFullYear();
    
                  //      doc.pageMargins = [20, 60, 20, 30];
                        // Set the font size fot the entire document
                        doc.defaultStyle.fontSize = 9;
                        // Set the fontsize for the table header
                        doc.styles.tableHeader.fontSize = 9;
                        // Create a header object with 3 columns
                        // Left side: Logo
                        // Middle: brandname
                        // Right side: A document title
                        doc['header'] = (function () {
                            return {
                                columns: [
    
                                    {
                                        alignment: 'left',
                                        italics: true,
                                        text: 'dataTables',
                                        fontSize: 18,
                                        margin: [10, 0]
                                    },
                                    {
                                        alignment: 'right',
                                        fontSize: 14,
                                        text: $("#drpIller option:selected").text() + "  " + $("#drpIlceler option:selected").text() 
                                    }
                                ],
                                margin: 20
                            }
                        });
                        doc['footer'] = (function (page, pages) {
                            return {
                                columns: [
                                    {
                                        alignment: 'left',
                                        text: ['Oluşturulma tarihi: ', { text: jsDate.toString() }]
                                    },
                                    {
                                        alignment: 'right',
                                        text: ['page ', { text: page.toString() }, ' / ', { text: pages.toString() }]
                                    }
                                ],
                                margin: 20
                            }
                        });
                        var objLayout = {};
                        objLayout['hLineWidth'] = function (i) { return .5; };
                        objLayout['vLineWidth'] = function (i) { return .5; };
                        objLayout['hLineColor'] = function (i) { return '#aaa'; };
                        objLayout['vLineColor'] = function (i) { return '#aaa'; };
                        objLayout['paddingLeft'] = function (i) { return 4; };
                        objLayout['paddingRight'] = function (i) { return 4; };
                        doc.content[0].layout = objLayout;
                    }
                    },
                    {
                        extend: 'print'
                    }
                    ],
                    "responsive": true,
                    "data": data,
                    "columns": [             
                       { "data": "A", "autoWidth": true},
                       { "data": "S", "autoWidth": true},
                       { "data": "D", "autoWidth": true },
                       { "data": "E", "autoWidth": true},
                       { "data": "F", "autoWidth": true },
                       { "data": "G", "autoWidth": true }
    
                    ],
                   "bAutoWidth": false 
                    }
                });
    

    谢谢你宝贵的帮助。

    1 回复  |  直到 7 年前
        1
  •  0
  •   mfg    7 年前

    我在这个链接上找到了答案: https://codepen.io/RedJokingInn/pen/XMVoXL 这是关于dom选项的。 我写的时候就解决了

    "dom":  '<"dt-buttons"Bf><"clear">lirtp'
    

    相反

     dom: 'Bfrtip'
    

    链接中的教程还包括打印页码和打印每页信息顶部的同一句话。

    也许将来能帮助别人。