需要DataTable打印才能只打印文本

Need DataTable Printing To Only Print Text

我有一个现有模块显示 table 中的数据(使用 DataTables (jQuery)),最终用户要求他们能够打印数据。

    $('.js-dataTable-full-agedDebt').DataTable({
            ajax: {
               url: 'inc/ajax/tables/payable/aged-debt.php',
               type: "post",
               data: function(d){
                   d.depot = Depot;
                   d.group = Group;
               }
            },
            dom: 'Bfrtip',
            pagingType: "full_numbers",
            buttons: [
                'print'
            ],
            order: [1., 'asc'],
            "deferRender": true,
            scrollY: "500px",
            paging: false,
            columns: [
                {"data": "Account"},
                {"data": "Term"},
                {"data": "Credit"},
                {"data": "Total"},
                {"data": "Amount"},
                {"data": "Month1"},
                {"data": "Month2"},
                {"data": "Month3"},
                {"data": "Month4"},
                {"data": "Month5"},
                {"data": "Action"},
                {"data": "balanceMonthRemit"},
                {"data": "balanceMonth"},
                {"data": "balanceMonthMinusOne"},
                {"data": "balanceMonthMinusTwo"},
                {"data": "balanceMonthMinusThree"},
                {"data": "balanceOlder"},
            ],
            "columnDefs": [
                {"visible": false, "targets": [11, 12, 13, 14, 15, 16]},
                {"orderData": [ 11 ], "targets": 4 },
                {"orderData": [ 12 ], "targets": 5 },
                {"orderData": [ 13 ], "targets": 6 },
                {"orderData": [ 14 ], "targets": 7 },
                {"orderData": [ 15 ], "targets": 8 },
                {"orderData": [ 16 ], "targets": 9 },
            ]
}

这在正常情况下没问题,但是,这个table没有默认值。 90% 的单元格中的值是带有 popOver 的锚标记(显示较小的数据table 显示计算)。

<a onmouseover="popupDataActivityTotal(&quot;CN000141-N&quot;)" onmouseout="popupDataActivityTotalClose(&quot;CN000141-N&quot;)" class="popOver" id="activityTotalCN000141-N" style="color:#3f9ce8;" data-toggle="popover" data-html="true" title="" data-placement="bottom" data-content="
                           
                <table class=&quot;table table-bordered table-striped&quot;>
                    <thead>
                        <th class=&quot;pl-15 pr-15&quot;>Doc Type</th>
                        <th class=&quot;pl-15 pr-15&quot;>Doc Num</th>
                        <th class=&quot;pl-15 pr-15&quot;>Doc Date</th>
                        <th class=&quot;pl-15 pr-15&quot;>Due Date</th>
                        <th class=&quot;pl-15 pr-15&quot;>Open Amount</th>
                    </thead>
                    <tbody>
                            <tr>
                                <td class=&quot;pl-15 pr-15&quot;>Invoice</td>
                                <td class=&quot;pl-15 pr-15&quot;>600054871</td>
                                <td class=&quot;pl-15 pr-15&quot;>18th June 2021</td>
                                <td class=&quot;pl-15 pr-15&quot;>18th June 2021</td>
                                <td class=&quot;pl-15 pr-15&quot;>£48.89</td>
                            </tr>
                            <tr>
                                <td class=&quot;pl-15 pr-15&quot;>Invoice</td>
                                <td class=&quot;pl-15 pr-15&quot;>600055336</td>
                                <td class=&quot;pl-15 pr-15&quot;>29th June 2021</td>
                                <td class=&quot;pl-15 pr-15&quot;>29th June 2021</td>
                                <td class=&quot;pl-15 pr-15&quot;>£601.32</td>
                            </tr>
                            <tr>
                                <td class=&quot;pl-15 pr-15&quot;>Invoice</td>
                                <td class=&quot;pl-15 pr-15&quot;>600055918</td>
                                <td class=&quot;pl-15 pr-15&quot;>13th July 2021</td>
                                <td class=&quot;pl-15 pr-15&quot;>13th July 2021</td>
                                <td class=&quot;pl-15 pr-15&quot;>£72.00</td>
                            </tr></tbody></table>
                        " data-original-title="Account Activity Total">
                        722.21
                    </a>

结果如下

我需要这些字段只显示 innerHTML/value 所以当我点击打印时,它不会像这样显示:

对于那些一直在观看该主题的人,我了解了出色的 DataTables 导出选项。

 buttons: [{extend: 'print',
            exportOptions: {
                columns: [ ':visible' ],
                format: {
                    body: function ( data, row, column, node ) {
                        if (column == 3) {
                            console.log($(data).text());
                            return column == 3 ?
     
                            $(data).text():
                            data;
                        } else if (column == 4) {
                            return column == 4 ?
     
                            $(data).text():
                            data;
                        
                        } else if (column == 5) {
                            return column == 5 ?
     
                            $(data).text():
                            data;
                        
                        } else if (column == 6) {
                            return column == 6 ?
     
                            $(data).text():
                            data;
                        
                        } else if (column == 7) {
                            return column == 7 ?
     
                            $(data).text():
                            data;
                        
                        } else if (column == 8) {
                            return column == 8 ?
     
                            $(data).text():
                            data;
                        
                        } else if (column == 9) {
                            return column == 9 ?
     
                            $(data).text():
                            data;
                        
                        } else {
                            return data;
                        }
                    }
                }
            },
        }],

我只能获取将文本嵌入到 HTML 中的列的文本。我本可以使用循环,但这是该项目的解决方法补丁,所以我相信其他人可以给出结构更好的答案