Datatables ExportOptions切换最后两个单元格

时间:2017-06-16 21:43:55

标签: javascript php jquery ajax datatables

我有一个DT表,其中包含我通过ajax更改的2个动态值,因此我需要为导出为PDF或EXCEL等时显示的新值执行一些代码。

在1个单元格中,我有一个select元素。在另一个单元格中,根据第一个单元格,我的值会发生变化。

我使用DT中的ExportOptions,因此我可以从打印中删除选择值,这样我就可以从其他单元格中获取更新的值。

问题:当我导出时,我使用ExportOptions切换的单元格切换,所以如果我有一个2行表,则2个第一个单元格将切换为下面的单元格。

My DT设置如下:

  var table = $('.broker-data-table').DataTable({
                "order": [[ 0, "desc" ]],
                dom: 'Bfrtlp',
                buttons: [
                    {
                        extend: 'pdfHtml5',
                        exportOptions : {
                            format: {
                                body: exportModify
                            }
                        },
                        orientation: 'landscape',
                        title: 'Investors Payment Information'
                    },
                    {
                        extend: 'csvHtml5',
                        exportOptions : {
                            format: {
                                body: exportModify
                            }
                        },
                        title: 'Investors Payment Information'
                    }
                ]
            });

exportModify函数:

function exportModify(data, row, col, node){
    if (col == 6) {

        return table
            .cell({row: row, column: col})
            .nodes()
            .to$()
            .children('span').text();

    } else if(col == 7) {

        return table
            .cell({row: row, column: col})
            .nodes()
            .to$()
            .text();

    } else {
        return data;
    }
}

这是我的表:

<table>
   <thead>
        <tr>
            <th>Beneficiary</th>
            <th>Email</th>
            <th>Bank Entity</th>
            <th>Bank Account</th>
            <th>Account Type</th>
            <th>Routing / Swift</th>
            <th>Month</th>
            <th>Total</th>
        </tr>
  </thead>
  <tbody>
        <?php foreach($data as $d): ?>
            <tr id="inv-<?= $d['id'] ?>">
                <td><?= $d['beneficiary'] ?></td>
                <td><?= $d['email'] ?></td>
                <td><?= $d['bank_entity'] ?></td>
                <td><?= $d['bank_account'] ?></td>
                <td><?= $d['account_type'] ?></td>
                <td><?= $d['routing_number'] ?></td>
                <td class="month-wraper" id="<?= $d['id'] ?>">
                    <span class="month-changer"><?= $d['payment_month'] ?></span>

                    <select class="month-select" id="<?= $d['id'] ?>">
                        <?php foreach($months_active as $m): ?>
                            <option value="<?= $m ?>"><?= $m ?></option>
                        <?php endforeach; ?>
                    </select>
                </td>
                <td class="payment-amount-td" id="<?= $d['id'] ?>"><?= $d['payment_amount'] ?></td>
            </tr>
        <?php endforeach; ?>
   </tbody>
</table>

这是表的外观(注意最后两列):

enter image description here

这是表格导出的方式(看看它们是如何切换的):

enter image description here

0 个答案:

没有答案