Search code examples
laravelyajra-datatable

DataTable is not a function, what's wrong?


I'm using datatable on a laravel project. But table is not rendering. It is showing the error:

Uncaught TypeError: $(...).DataTable is not a function
    at HTMLDocument.<anonymous> (dashboard:147)
    at l (datatables.min.js:14)
    at c (datatables.min.js:14)

I've included jQuery, js and css as following order

  • jQuery
  • datatable js
  • datatable css

what else might cause the problem?


Solution

  • make sure to load the jquery.js before the preferred dataTable.js file.

    <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>