getting an erorr

getting an erorr

erumerum Posts: 9Questions: 4Answers: 0
edited February 2018 in Free community support
**Uncaught TypeError: $(...).DataTable is not a function
    at HTMLDocument.<anonymous> (index:270)
    at fire (jquery-1.12.4.js:3232)
    at Object.fireWith [as resolveWith] (jquery-1.12.4.js:3362)
    at Function.ready (jquery-1.12.4.js:3582)
    at HTMLDocument.completed (jquery-1.12.4.js:3617)**

@model IEnumerable<CallCenterCRM.Models.EmpDeptViewModel>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>



<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table id="table_id"       class="table table-condensed table-striped table-hover">
    <thead>
        <tr>

            <th>
                @Html.DisplayNameFor(model => model.Department)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Abbreviation)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.prefix)
            </th>
            <th>
                @Html.DisplayName("Department Incharge")
            </th>
            <th></th>
        </tr>
        </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>

                <td>
                    @Html.DisplayFor(modelItem => item.Department)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Abbreviation)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.prefix)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.SelectedEmployee)
                </td>
                <td>
                    @*@Html.ActionLink("Edit", "Edit", new { id=item.DepartmentID }) |
                        @Html.ActionLink("Details", "Details", new { id=item.DepartmentID }) |
                        @Html.ActionLink("Delete", "Delete", new { id=item.DepartmentID })*@
                </td>
            </tr>
        }
    </tbody>

</table>
@section scripts{
    <script>
        $(document).ready(function () {
            $("#table_id").DataTable({
                "pagingType": "full_numbers",
                columns: [

          
           {

               data: null, 

               className: "center",

                    defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'

        }

        ]

            });
        });
        $('#table_id').on('click', 'a.editor_edit', function (e) {

            e.preventDefault();

 

            editor.edit( $(this).closest('tr'), {

                title: 'Edit record',

            buttons: 'Update'

        } );

        } );

    </script>

}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>

    @Styles.Render("~/Content/css")
    @Styles.Render("~/Content/themes/base/css")
   
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryui")
    
    @Scripts.Render("~/bundles/bootstrap")

  

    <link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet" />
    <link href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css" rel="stylesheet" />

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

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
      
    @*//code.jquery.com/jquery-1.12.4.js*@
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

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


    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>

    @*<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.1/js/buttons.colvis.min.js"></script>*@



    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
    @*<script src=" https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>*@

    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">


    <script src="~/Scripts/jquery-ui.js"></script>



</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                @*@Html.Partial("_LoginPartial")*@
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>
    @RenderSection("scripts", required: false)
</body>
</html>

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • kthorngrenkthorngren Posts: 20,332Questions: 26Answers: 4,774

    It looks like you are loading jQuery twice:

    @Scripts.Render("~/bundles/jquery")

    and

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

    It should only be loaded once. The error you are getting is many times caused by loading jQuery multiple times.

    Kevin

This discussion has been closed.