数据表导出数据中缺少表单输入

问题描述 投票:0回答:1

我有这个Html:

<div class="table-responsive">
    <div id="product_purchase_report_table_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
        <div class="dt-buttons btn-group">
            <a class="btn btn-default buttons-csv buttons-html5 btn-sm" tabindex="0" aria-controls="product_purchase_report_table" href="#">
                <span><i class="fa fa-file-csv" aria-hidden="true"></i> Export to CSV</span>
            </a>
            <a class="btn btn-default buttons-excel buttons-html5 btn-sm" tabindex="0" aria-controls="product_purchase_report_table" href="#">
                <span><i class="fa fa-file-excel" aria-hidden="true"></i> Export to Excel</span>
            </a>
            <a class="btn btn-default buttons-print btn-sm" tabindex="0" aria-controls="product_purchase_report_table" href="#">
                <span><i class="fa fa-print" aria-hidden="true"></i> Print</span>
            </a>
            <a class="btn btn-default buttons-collection buttons-colvis btn-sm" tabindex="0" aria-controls="product_purchase_report_table" href="#">
                <span><i class="fa fa-columns" aria-hidden="true"></i> Column visibility</span>
            </a>
            <a class="btn btn-default buttons-pdf buttons-html5 btn-sm" tabindex="0" aria-controls="product_purchase_report_table" href="#">
                <span><i class="fa fa-file-pdf" aria-hidden="true"></i> Export to PDF</span>
            </a>
        </div>
        <div id="product_purchase_report_table_filter" class="dataTables_filter">
            <label><input type="search" class="form-control input-sm" placeholder="Search ..." aria-controls="product_purchase_report_table" /></label>
        </div>
        <table class="table table-bordered table-striped dataTable" id="product_purchase_report_table" role="grid" aria-describedby="product_purchase_report_table_info">
            <thead>
                <tr role="row">
                    <th class="sorting_asc" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Date: activate to sort column descending" style="width: 56.7656px;">Date</th>
                    <th class="sorting" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-label="Supplier: activate to sort column ascending" style="width: 386.305px;">Supplier</th>
                    <th class="sorting" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-label="Product: activate to sort column ascending" style="width: 104.383px;">Product</th>
                    <th class="sorting" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-label="Reference No.: activate to sort column ascending" style="width: 103.508px;">Reference No.</th>
                    <th class="sorting" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-label="Quantity: activate to sort column ascending" style="width: 62.1953px;">Quantity</th>
                    <th class="sorting_disabled" rowspan="1" colspan="1" aria-label="PCs" style="width: 86.0312px;">PCs</th>
                    <th class="sorting" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-label="Unit Purchase Price: activate to sort column ascending" style="width: 142.883px;">
                        Unit Purchase Price
                    </th>
                    <th class="sorting" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-label="Subtotal: activate to sort column ascending" style="width: 69.4141px;">Subtotal</th>
                    <th class="sorting" tabindex="0" aria-controls="product_purchase_report_table" rowspan="1" colspan="1" aria-label="Average (Kgs) / Pc: activate to sort column ascending" style="width: 133.516px;">Average (Kgs) / Pc</th>
                </tr>
            </thead>

            <tbody>
                <tr role="row" class="odd">
                    <td class="sorting_1">02-10-2023</td>
                    <td>
                        mr Omar Salim Mwakuzinya - AUTO REPAIRS
                    </td>
                    <td>01. Whole Chicken</td>
                    <td>5412</td>
                    <td>1200</td>
                    <td style="max-width: 70px !important;" class="mobile">
                        <div class="form-group">
                            <input class="form-control" value="0.00" name="pcs" type="number" id="pcs" data-code="55" data-value="0.00" style="width: 70px !important;" />
                        </div>
                    </td>
                    <td>300.00</td>
                    <td>360,000.00</td>
                    <td>0</td>
                </tr>
                <tr role="row" class="even">
                    <td class="sorting_1">02-10-2023</td>
                    <td>
                        mr Omar Salim Mwakuzinya - AUTO REPAIRS
                    </td>
                    <td>11. Gizzard</td>
                    <td>5412</td>
                    <td>3.5</td>
                    <td style="max-width: 70px !important;" class="mobile">
                        <div class="form-group">
                            <input class="form-control" value="0.00" name="pcs" type="number" id="pcs" data-code="56" data-value="0.00" style="width: 70px !important;" />
                        </div>
                    </td>
                    <td>200.00</td>
                    <td>700.00</td>
                    <td>0</td>
                </tr>
                
            </tbody>
            <tfoot>
                <tr class="bg-gray font-17 footer-total text-center">
                    <td colspan="4" rowspan="1">Total:</td>
                    <td rowspan="1" colspan="1">1449.06</td>
                    <td rowspan="1" colspan="1">204</td>
                    <td rowspan="1" colspan="1">297.00</td>
                    <td rowspan="1" colspan="1">430,366.68</td>
                    <td rowspan="1" colspan="1">&nbsp;</td>
                </tr>
            </tfoot>
        </table>
        <div class="dataTables_info" id="product_purchase_report_table_info" role="status" aria-live="polite">Showing 1 to 11 of 11 entries</div>
        <div class="dataTables_paginate paging_simple_numbers" id="product_purchase_report_table_paginate">
            <ul class="pagination">
                <li class="paginate_button previous disabled" id="product_purchase_report_table_previous"><a href="#" aria-controls="product_purchase_report_table" data-dt-idx="0" tabindex="0">Previous</a></li>
                <li class="paginate_button active"><a href="#" aria-controls="product_purchase_report_table" data-dt-idx="1" tabindex="0">1</a></li>
                <li class="paginate_button next disabled" id="product_purchase_report_table_next"><a href="#" aria-controls="product_purchase_report_table" data-dt-idx="2" tabindex="0">Next</a></li>
            </ul>
        </div>
    </div>
</div>

这会产生这个数据表:

我的问题是,当我以任一方式(pdf、excel 等)导出数据时,表单输入数据(PC 列)为空白。我是否像其他列一样将输入导出为文本?我需要导出所有列,包括表单输入列。我正在使用 Datatables CDN 库

datatables
1个回答
0
投票

是的,这是可能的。

基本上,使用取自 Datatables 论坛 的这段代码:

body: function ( data, row, column, node ) 
{
return $(data).is("div") ?
$(data).find('input').val():
data;
}
© www.soinside.com 2019 - 2024. All rights reserved.