-2

I am starting out on Asp.net MVC using Mosh Complete MVC Course on Udemy as a learning guide..Currently trying to implement the default JQuery Datatable with not configuration..Everything works fine until this line is added

$("#customers").DataTable();

I have tried updating bootstrap and jquery but still no luck. At the console i get no error message..but it just does not work. Please help a newbie. Thanks.

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
  • Did you install table jquery plugin ? – ISHIDA Jun 09 '17 at 15:11
  • what is the error message you are getting (check your console) ? – Munzer Jun 09 '17 at 15:12
  • I'm sorry...I'm new to this..been trying to debug my app and found this error at the console.. jQuery.Deferred exception: cannot read property 'mData' of undefined TypeError: Cannot read property'mData'of type undefined... – Andrew Aghoghovwia Jun 09 '17 at 16:44
  • See https://stackoverflow.com/questions/25377637/datatables-cannot-read-property-mdata-of-undefined – James P Jun 09 '17 at 16:54
  • Try this video https://learn.microsoft.com/en-us/aspnet/web-forms/videos/jquery/how-do-i-make-ajax-calls-using-jquery – htm11h Jun 09 '17 at 18:53
  • sounds like your includes are missing or out of order. Is your code inside a $(document).ready? – Bindrid Jun 12 '17 at 03:41

4 Answers4

0

1st add jquery-1.12.4.js before using

https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css
https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js

then use

$(document).ready(function(){
    $('#myTable').DataTable();
});

It will work fine.

0

DataTables requires a well-formed table. It must contain and tags, otherwise it throws this error. Also, make sure that you have the same amount of table data in your project.

GoGo
  • 2,727
  • 5
  • 22
  • 34
0

i had the same issue, to solve it make sure your table is organized properly. The heading should be wrapped in a thead and the body in tbody and also the title rows amount should be the same as the body row amount. example of a table that will work with datatables

<table id="sample-table">
<thead>
    <tr>
        <th>title-1</th>
        <th>title-2</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>data-1</td>
        <td>data-2</td>
        <td>data-3</td>
    </tr>
</tbody>

jermaine
  • 9
  • 1
0

Firstly, you need to know that DataTables needs that your table is in a well formatted. Check if there is a condition that you will control the appearance of a column or not. You need to make the tag outside the if condition. you will check the other format problem that will cause that your table is not well formatted. As you see here in this picture the tag outside the if condition.