DataTables warning (table id = 'table-filter'): requested unknown parameter '0' from data source for row 0 error in data tables

I have a table in which data comes from a database. I use data tables in this table. But the problem is that there is no row in the database, it displays a warning

DataTables warning (table id = 'table-filter'): Requested unknown parameter '0' from the data source for row 0 

My jQuery code for the table:

 $('#table-filter').dataTable({ "bPaginate": true, "bProcessing": false, "bStateSave": false, "aLengthMenu": [[5, 10, 20, 50, 100 , -1], [5, 10, 20, 50, 100, "All"]], "iDisplayLength" : 5, "sPaginationType": "full_numbers", "aoColumnDefs": [ { 'bSortable': false, 'aTargets': [ 0,7 ] } ], "oLanguage": { "sLengthMenu": "Show _MENU_ records per page", "sZeroRecords": "Nothing found - sorry", "sInfo": "Showing _START_ to _END_ of _TOTAL_ Entries", "sInfoEmpty": "Showing 0 to 0 of 0 records", "sInfoFiltered": "(filtered from _MAX_ total records)" } }).columnFilter({ aoColumns:[ null, { type: "text" }, { type: "text" }, { type: "text" }, { type: "text" }, { type: "text" }, { type: "text" } ], }); 

What can I do for this?

+4
source share
1 answer

You need to include "aaData" in your initialization, for example:

 $('#table-filter').dataTable({ ... "aaData": [2,3,5,7], ... } 

Alternatively, you can avoid creating a table if it does not exist (at the suggestion of Saranya Sadhasivam).

You can use something like:

  if ( $('#table-filter tr').length > 0 ) { ... } 

Or, if the database just takes time to load, add a callback that will begin initialization after the data has arrived.

My experience with dataTables is that I don't like to initialize without at least one full and complete line. Once this is created, it can be sorted / filtered / etc to null elements and work fine, but it needs to start with something.

+1
source

All Articles