Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When I try to retrieve data from my database to the 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>

The JSON data retrieved:

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

Below is my table:

<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 (ignited datatables)

$this->load->library('datatables');

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

I'm using codeigniter and DataTables.

Why am I getting that error and how to retrieve the data to the table?

like image 706
LiveEn Avatar asked Sep 05 '12 11:09

LiveEn


2 Answers

I also had the same issue. The issue 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> will fix your error. One more thing,If no data is available It will display the message automatically you need not display the message.In this case you can remove this as it will be done automatically:

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

In order to customize the message pass this as an option "sEmptyTable": "Loading data from server"

$('.datatable ).dataTable({
  "bFilter": false,
   "bPaginate": false,
   "bLengthChange": false,
   "bInfo": false,
   "oLanguage": {
    "sEmptyTable": '',
    "sInfoEmpty": ''
   },
   "sEmptyTable": "Loading data from server"
 });
like image 108
Sachin Prasad Avatar answered Oct 21 '22 13:10

Sachin Prasad


You are using the POST method to get the data. If you follow php the example that is provided with datatables, the GET method is used. I assume that when you use sorting or searching all the requests are GETs.

like image 20
JvdBerg Avatar answered Oct 21 '22 14:10

JvdBerg