在jquery数据表中单击按钮时,两个页脚未以pdf和excel格式打印

时间:2018-06-11 07:15:38

标签: javascript jquery datatables

Actaullay我有按钮保存为pdf和excel格式。我有两个来自json的页脚为Total和Percentage。当我点击Button然后只有Total footer即将到来但是Percentage行不会出现在pdf和excel中files.I需要显示页脚,但它不会出现。

<table id="report46Table" class="display responsive nowrap" style="width: 100%">
                    <thead>
                        <tr>
                            <th>Disturbance</th>
                            <th>Zero</th>
                            <th>Minor</th>
                            <th>Medium</th>
                            <th>Major</th>
                            <th>Total</th>
                            <th>Occurance</th>
                        </tr>
                    </thead>
                    <tfoot>
                    <tr id="fTotal">
                        <th>Total</th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                    </tr>
                        <tr id="fPercentage">
                            <th>Total</th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>

                    </tfoot>

                </table>

加载数据表的脚本是:

<script>
    $(document).ready(function() {
        var report46Data = [];
        var report46Footer = null;
        var report46Table = $('#report46Table').DataTable({
            data : report46Data,
            dom: 'Bfrtip',
            buttons: [
                'copy',
                {
          extend: 'excel',
          footer: true,
        text : 'Export to Excel',

          messageTop: 'Records of forest disturbances in the forest',
              filename: function(){

                  return 'report46';
              },
                },

                {
        extend: 'pdfHtml5',
        footer: true,
        //orientation : 'landscape',
        pageSize: 'TABLOID',
        text : 'Export to Pdf',
        messageTop: 'Records of forest disturbances in the forest',
        title: '',
        filename: function(){

                return 'report46';
            },
                },

            ],
            ordering: false,
            "paging" :false,
            columns : [ {
                "data" : "disturbanceName"
            }, {
                "data" : "iZero"
            }, {
                "data" : "iMinor"
            }, {
                "data" : "iMedium"
            } ,{
                "data" : "iMajor"
            },{
                "data" : "total"
            },{
                "data" : "occurance"
            }],
            "footerCallback" : function(row, data, start, end, display) {
                var api = this.api();
                if (report46Footer) {
                    $($("#fTotal")[0].cells[0]).html(report46Footer[0].disturbance);
                    $($("#fTotal")[0].cells[1]).html(report46Footer[0].iZero);
                    $($("#fTotal")[0].cells[2]).html(report46Footer[0].iMinor);
                    $($("#fTotal")[0].cells[3]).html(report46Footer[0].iMedium);
                    $($("#fTotal")[0].cells[4]).html(report46Footer[0].iMajor);
                    $($("#fTotal")[0].cells[5]).html(report46Footer[0].total);
                    $($("#fTotal")[0].cells[6]).html("");

                    $($("#fPercentage")[0].cells[0]).html(report46Footer[1].disturbance);
                    $($("#fPercentage")[0].cells[1]).html(report46Footer[1].iZero);
                    $($("#fPercentage")[0].cells[2]).html(report46Footer[1].iMinor);
                    $($("#fPercentage")[0].cells[3]).html(report46Footer[1].iMedium);
                    $($("#fPercentage")[0].cells[4]).html(report46Footer[1].iMajor);
                    $($("#fPercentage")[0].cells[5]).html(report46Footer[1].total);
                    $($("#fPercentage")[0].cells[6]).html("");
                }
            }
        });

        $.ajax({
            url : A_PAGE_CONTEXT_PATH + "/api/report46/all",
            method : "GET",
            dataType : "json",
            success : function(response) {
                report46Data = response.dataList;
                report46Footer = response.footer;

                report46Table.rows.add(report46Data).draw();
            }

        });

    });
</script>

enter image description here

0 个答案:

没有答案