question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I get the following error in the console when I try to use DataTables

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

I ran the following code to setup dataTables gem ‘jquery-datatables-rails’, ‘~> 3.3.0’ bundle install $ rails generate jquery:datatables:install $ rails generate jquery:datatables:install bootstrap3 $ rails generate jquery:datatables:install responsive

I restarted the rails server, and added this code.

//my_javascript.js
$(document).ready(function(){
  $('#test-table').DataTable({
        responsive: true
    });
});
//my_erb_file.erb
 <table class="display" id="test-table">
          <thead>
          <tr>
            <th>Name</th>
            <th>Job</th>
            <th>Start date</th>
            <th>Location</th>
            <th>Desk Location</th>
            <th>Manager</th>
            <th>Status</th>
          </tr>
          </thead>
          <tbody>
              <tr class="options">
                <td>test</td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                <td>test</td>
                <td>test</td> 
              </tr>
          </tbody>
        </table>

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

18reactions
utkarshrai003commented, May 26, 2017

I solved it. The Issue was jQuery was being initialised twice. Once before requiring the datatable and once after it was initialised and all set to work. So it was something like this.

//= require jquery //= require jquery_ujs //= require dataTables/jquery.dataTables //= require dataTables/bootstrap/3/jquery.dataTables.bootstrap //= require tree.

And in the javascript directory, somehow an extra jquery.min.js file was there. So when //= require tree . was executed, Jquery was reinitialized once more and lost all the references to datatables.

Hope this may be useful for someone.

0reactions
Divyakalaicommented, Aug 14, 2019

jquery.min.js:2 jQuery.Deferred exception: $(…).DataTable is not a function TypeError: $(…).DataTable is not a function at HTMLDocument.<anonymous> (http://localhost/Newtheme/clients/clientlist:1012:20) at l (http://localhost/Newtheme/assets/theme/plugins/jquery/jquery.min.js:2:29375) at c (http://localhost/Newtheme/assets/theme/plugins/jquery/jquery.min.js:2:29677) undefined w.Deferred.exceptionHook @ jquery.min.js:2 jquery.min.js:2 Uncaught TypeError: $(…).DataTable is not a function at HTMLDocument.<anonymous> (clientlist:1012) at l (jquery.min.js:2) at c (jquery.min.js:2)

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

admin lte 3 datatable not working for me… any one pls help me

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: $(...).DataTable is not a function - Stack Overflow
A potential issue to achieve "TypeError: $(…).DataTable is not a function" since Datatables started providing a pick-your-own download builder ...
Read more >
TypeError: $(...).DataTable is not a function in jQuery
To solve the "$(...).DataTable is not a function" jQuery error, make sure to load the jQuery library before loading the DataTables library. The...
Read more >
Uncaught TypeError: $(...).DataTable(...) is not a function only ...
This code works perfectly. The default view is loaded with controls and the datatable functionality works.
Read more >
TypeError DataTable is not a function | Edureka Community
This happened because the jQuery DataTables library is missing or the jQuery library is loaded after jQuery DataTables. This can be solved by ......
Read more >
Uncaught TypeError: $(…).DataTable is not a function at ...
Uncaught TypeError : $(…).DataTable is not a function at HTMLDocument. How do I solve the DataTable Laravel problem in 03 days? Hi I'm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found