Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables warning (table id = 'ideas'): cannot reinitialise data table

I am using data tables and am adding options to the JS code, the changes work but I keep on getting a popup warning. How can I stop the warning?

$(document).ready(function() {
    $('#ideas').dataTable( {
        "aLengthMenu": [[5, 10, 15, -1], [5, 10, 50, "All"]]
    });
});

enter image description here

like image 825
steve0nz Avatar asked Jun 17 '13 04:06

steve0nz


2 Answers

If you just want to get rid of the alert box (eg "stop the warning") add this as the first line of your $(document).ready :

$.fn.dataTableExt.sErrMode = 'throw';

Now datatables will throw an error visible as "uncaught error: Datatables warning ..." in the console instead of the ugly alert-box.

However, you have an error in your code / data regardless the error now is thrown silently.

The error "DataTables warning (table id = 'XXX'): Requested unknown parameter 'XXX' from the data source for row X" is raised when there is a mismatch between the number of columns in the <table> and the number of columns in the data.

<thead>
  <th>col A</th>
  <th>col B</th>
</thead>

Inserting

<tr>
  <td>test test</td>
</tr>

or

<tr>
  <td colspan="2">test test</td>
</tr>

Would reproduce exactly that error. So examine your data again ..

like image 116
davidkonrad Avatar answered Sep 23 '22 18:09

davidkonrad


You should use "bDestroy": true prop in order to populate table during post back

like image 22
user2481943 Avatar answered Sep 20 '22 18:09

user2481943