Requested unknown parameter '1' from data source for row 0 in DataTables

When I try to retrieve data from my database into a table, I get this error:

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

Below is the javascript that I used

 <script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#student_table').dataTable( { "bProcessing": true, "bServerSide": true, "sServerMethod": "POST", "sAjaxSource": "<?php echo base_url()?>index.php/data/all" } ); } ); </script> 

Received JSON data:

 {"sEcho":0,"iTotalRecords":3, "iTotalDisplayRecords":3, "aaData":[["85","t1","1D"],["74","test475","4A"], ["777","maiz","5"]],"sColumns":"id,name,class"} 

The table below is:

 <table class="datatable tables" id="student_table"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Class</th> </tr> </thead> <tbody> <tr> <td class="dataTables_empty">Loading data from server</td> </tr> </tbody> </table> 

PHP code (flammable data)

 $this->load->library('datatables'); $this->datatables->select('admission,name,class'); $this->datatables->from('students'); echo $this->datatables->generate(); 

I use codeigniter and DataTables.

Why am I getting this error and how to retrieve data in a table?

+6
source share
4 answers

I had the same problem too. The problem is here:

 <tr> <td class="dataTables_empty">Loading data from server</td> </tr> 

You have three <TH> but only one <td> Adding two more <td> fix your error. One more thing: if there is no data, a message will be displayed automatically, you do not need to display a message. In this case, you can delete this, as it will be done automatically:

 <tr> <td class="dataTables_empty">Loading data from server</td> </tr> 

To configure the message, pass this as the "sEmptyTable": "Loading data from server" option "sEmptyTable": "Loading data from server"

 $('.datatable ).dataTable({ "bFilter": false, "bPaginate": false, "bLengthChange": false, "bInfo": false, "oLanguage": { "sEmptyTable": '', "sInfoEmpty": '' }, "sEmptyTable": "Loading data from server" }); 
+14
source

You use the POST method to receive data. If you follow the php example provided by datatables , the GET method is used. I assume that when you use sorting or searching, all queries are GET.

+1
source

A couple of ideas that can help ...

So it can ruin it.

  1. If this is something else, maybe look at here ... maybe some help.

Good luck.

0
source

We had similar problems ...

But, before you go crazy - check the data in the tables. In our case, our data had hyperlinks and curly quotes used in the data that populated the table — these quotation quotes were removed when the data was loaded from the CSV file. The story that IE could not handle it, but Chrome and Firefox ignored it.

0
source

Source: https://habr.com/ru/post/924622/


All Articles