简体   繁体   English

按钮未显示在数据表上

[英]Buttons not showing on Datatables

I am currently using adminlte with mvc to create a project.我目前正在使用 adminlte 和 mvc 创建一个项目。

This is my Main.css datatables css这是我的 Main.css 数据表 css

pdfmake js pdjmake js pdfmake js pdjmake js

vfs_fonts js vfs fonts js vfs_fonts js vfs fonts js

datatables js datatables js数据表js 数据表js

My datatables comes out fine but the buttons are not appending.我的数据表很好,但按钮没有附加。 I had taken the example from the datatables page inside adminlte.我从 adminlte 的数据表页面中获取了示例。

数据表示例

how it should look:它应该如何看: 在此处输入图像描述

cshtml page: cshtml 页面:

<div class="wrapper">
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>DataTables</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active">DataTables</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">DataTable with default features</h3>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
                <table id="example1" class="table table-bordered table-striped">
                    <tr>
                        <th>
                            @Html.DisplayNameFor(model => model.Stage)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Name)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Email)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Phone)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Website)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.MangoContact)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Notes)
                        </th>

                        <th>
                            @Html.DisplayNameFor(model => model.DateAdded)
                        </th>
                        <th></th>
                    </tr>

                    @foreach (var item in Model)
                    {
                        <tr>
                            <td>
                                @Html.DisplayFor(modelItem => item.Stage)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Name)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Email)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Phone)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Website)
                            </td>

                            <td>
                                @Html.DisplayFor(modelItem => item.MangoContact)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Notes)
                            </td>

                            <td>
                                @Html.DisplayFor(modelItem => item.DateAdded)
                            </td>
                            <td>
                                @Html.ActionLink("Edit", "Edit", new { id = item.ClientID }) |
                                @Html.ActionLink("Details", "Details", new { id = item.ClientID }) |
                                @Html.ActionLink("Delete", "Delete", new { id = item.ClientID })
                            </td>
                        </tr>
                    }
                </table>
            </div>
            <!-- /.card-body -->
        </div>
        <!-- /.card -->
    </section>
</div>

scripts section:脚本部分:

    @section scripts {
<script type="text/javascript" charset="utf8">
    $(function () {
        $("#example1").DataTable({
            "responsive": true, "lengthChange": false, "autoWidth": false,
            "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
        }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
</script>}

BundleConfig.cs BundleConfig.cs

    public class BundleConfig
{
    // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                    "~/Scripts/bootstrap.bundle.min.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/Datatables/css/Main.css",
                  "~/adminlte/plugins/fontawesome-free/css/all.min.css",
                  "~/adminlte/css/adminlte.min.css",
                  "~/Content/site.css"));

        bundles.Add(new ScriptBundle("~/adminlte/js").Include(
                  "~/adminlte/js/adminlte.min.js"));

        bundles.Add(new ScriptBundle("~/Scripts/DataTables/").Include(
            "~/Content/Datatables/js/pdfmake.min.js",
            "~/Content/Datatables/js/vfs_fonts.js",
            "~/Content/Datatables/js/datatables.min.js"));
    }
}}

Something simple was missing <thead></thead> tags.缺少<thead></thead>标签的一些简单的事情。

Thanks to andrewjames for the helpful links all working now!感谢 andrewjames 提供的有用链接现在都可以使用了!

Hi I am facing same issue and have thead tag too.您好,我也面临同样的问题,并且也有 thead 标签。 Can anyone help me out谁能帮我吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM