TypeError: $(...).DataTable is not a function TypeError: $(...).DataTable is not a function asp.net asp.net

TypeError: $(...).DataTable is not a function


CAUSE

There could be multiple reasons for this error.

  • jQuery DataTables library is missing.
  • jQuery library is loaded after jQuery DataTables.
  • Multiple versions of jQuery library is loaded.

SOLUTION

Include only one version of jQuery library version 1.7 or newer before jQuery DataTables.

For example:

<script src="js/jquery.min.js" type="text/javascript"></script><script src="js/jquery.dataTables.min.js" type="text/javascript"></script>

See jQuery DataTables: Common JavaScript console errors for more information on this and other common console errors.


This worked for me. But make sure to load the jquery.js before the preferred dataTable.js file. Cheers!

<script type="text/javascript" src="~/Scripts/jquery.js"></script><script type="text/javascript" src="~/Scripts/data-table/jquery.dataTables.js"></script> <script>$(document).ready(function () {    $.noConflict();    var table = $('# your selector').DataTable();});</script>


I got this error because I found out that I referenced jQuery twice.

The first time: on the master page (_Layout.cshtml) in ASP.NET MVC, and then again on one current page so I commented out the one on the master page.

If you are using ASP.NET MVC this snippet could help you

@*@Scripts.Render("~/bundles/jquery")*@//comment this line @Scripts.Render("~/bundles/bootstrap")@RenderSection("scripts", required: false)

and in the current page I added these lines

<script src="~/scripts/jquery-1.10.2.js"></script><!-- #region datatables files --><link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" /><script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script><!-- #endregion -->

Hope this help you even if don't use ASP.NET MVC