2
votes

I am using laravel 5.4 and Yajra Datatable but i cannot make it work .. I am having a problem with this "Uncaught TypeError: $(...).DataTable is not a function"

here is my code

  <script src="https://datatables.yajrabox.com/js/jquery.min.js"></script>
$(function() { $('#users-tbl').DataTable({ processing: true, serverSide: true, ajax: 'http://localhost/bostonbakers/public/employee/table', columns: [ {data:'id'}, {data:'email'}, {data:'password'} ] }); });
<script src="{{ asset('js/app.js') }}"></script>

What should i do?

1

1 Answers

0
votes

I think this error occours because of Order of scripts. It is important when they are dependent on libraries or other scripts.

Any jQuery related code needs to be included after jQuery.js... that means plugins and any code you write that uses jQuery. Similarly any code you write that uses a plugin must have the plugin loaded before your code.

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" charset="utf8" src="/js/jquery.dataTables.js"></script>

Also make sure you have only include jQuery once in a page...not once per plugin as some occasionally do