【问题标题】:How to resolve non rendering DataTable export buttons?如何解决非呈现 DataTable 导出按钮?
【发布时间】:2016-05-30 11:17:25
【问题描述】:

我正在关注 guide on adding file export buttons 到现有的 DataTable。

但是当我运行 asp 解决方案时,导出按钮按预期工作,但无法正确呈现,仅显示按钮的文本。

我重新检查了脚本引用的顺序,这些引用反映了上面链接的指南的设置。

问题:

为了呈现 DataTable 按钮,脚本的正确顺序是什么?

它们在运行时的样子:

它们应该是什么样子:

脚本和 HTML(要点):

@model System.Data.DataTable


<div class="container">
    <hr/>



        <div class="form-group">

                    <div class="table-responsive">
                        <div class="table-responsive" id="datatable-wrapper">
                            <style>
                                #escalation tr > *:nth-child(1) {
                                    display: none;
                                }
                            </style>
                            <table id="escalation" class="table table-striped table-bordered" cellspacing="0" width="100%">
                                <thead>
                                    <tr>
                                        @foreach (System.Data.DataColumn col in Model.Columns)
                                        {
                                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">@col.Caption</th>
                                        }
                                        <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Details</th>
                                        <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Delete</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (System.Data.DataRow row in Model.Rows)
                                    {
                                        <tr>
                                            @foreach (var cell in row.ItemArray)
                                            {
                                                <td style="font-size:11px">@cell.ToString()</td>
                                            }
                                            <td><button type="submit" style="background-color: #0CA281;" class="btn btn-success details">Details</button></td>
                                            <td><button type="submit" class="btn btn-danger delete">Delete</button></td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>
        </div>
    </div>



<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>

<script src="https://cdn.datatables.net/buttons/1.2.1/js/buttons.flash.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.1/css/buttons.dataTables.min.css"></script>

<script src="https://cdn.datatables.net/buttons/1.2.1/js/dataTables.buttons.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.1/js/buttons.print.min.js"></script>


<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<script>



    $(document).ready(function () {



        var historyTable = $('#escalation').DataTable({
            "order": [[6, "desc"]],
            buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
            ],
            "sSwfPath": "../Content/dataTables/swf/copy_csv_xls.swf"          
        });

        historyTable.buttons().container()
        .insertAfter( '#datatable-wrapper' );




    });
</script>

【问题讨论】:

  • 能否请您也发布您的 HTML?
  • @vijayP 我现在在上面发布了我的 HTML..仍然不确定问题是什么?

标签: jquery css datatables datatable-buttons


【解决方案1】:

尝试添加DOM parameter

 order: [[6, "desc"]],
 dom: "Bfrtip",
 buttons: [
    'copy', 'csv', 'excel', 'pdf', 'print'
]

更多关于这个参数Here的信息,希望对你有帮助!

更新: 您可以使用Datatables download builder 并包含按钮扩展名。只需确保包含相关的 css(我假设构建器包含它)。以防万一,This is the minified version of the buttons css

【讨论】:

  • 这并没有解决问题,我认为该道具只是指定了工具栏相对于我的表格的位置。还有其他想法吗?
  • 更新了答案。我实际上认为它对我有用,但事实并非如此。添加相关的 css 对我来说就足够了。
猜你喜欢
  • 2018-01-25
  • 2016-05-20
  • 1970-01-01
  • 2018-10-21
  • 2021-04-13
  • 1970-01-01
  • 2017-12-02
  • 1970-01-01
  • 2022-01-18
相关资源
最近更新 更多