5

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?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
LiveEn
  • 3,193
  • 12
  • 59
  • 104

4 Answers4

13

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"
 });
Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101
1

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.

JvdBerg
  • 21,777
  • 8
  • 38
  • 55
0

Couple of ideas which might help...

  1. Make sure your response from server is correctly formatted JSON, with correct header. e.g. https://stackoverflow.com/a/4064468/661584 not sure about igniter / php myself but may be an issue.

  2. Not sure the sColumns param is correct there on its own, think that's for reordering of cols on client... and only used with sName see http://datatables.net/usage/columns#sName and http://datatables.net/usage/server-side

So that might be messing it up.

  1. If its something else, maybe look at answer here... might be some help.

Good luck

Community
  • 1
  • 1
MemeDeveloper
  • 6,457
  • 2
  • 42
  • 58
0

We were having similar issues...

But, before you go nuts - check the data in the tables. In our case, our data had hyperlinks and curly quotes used in the data that populated the table - those quotes curly quotes were getting stripped out when the data was uploaded from a CSV file. Short story is that IE couldn't deal with it, but Chrome and Firefox ignored it.