Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables requested unknown parameter '0' for row 0

I've got this problem when i try to get data from clients table in the database

DataTables warning: table id=example - Requested unknown parameter '0' for row 0. For more information about this error, please see http://datatables.net/tn/4

This is my Controller in Codeigniter

class Clients extends CI_Controller  {

    function header()
    {
        $data['hms'] = $this->config->item('page_title');
        $this->load->view('header3',$data);
    }

    public function index()
    {

        //$this->datatables->select('*');
        //$this->datatables->from('bookitguests');
        //$data['clients'] = $this->datatables->generate();
        $data = "";
        $this->header();
        $this->load->view('all_guests',$data);
    }

    public function TableClients()
    {
        $this->datatables->select('name, surname, email')->from('bookitguests');
        echo $this->datatables->generate();
    }

}

This is my view in Codeigniter (ps, im not adding the header file, its too long)

<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.1/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.1/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" charset="utf-8">
    $(document).ready(function() {
        $('#example').DataTable( {
            "bProcessing": false,
            "bServerSide": false,
            "sAjaxSource": "<?php base_url(); ?>clients/TableClients",
            "sServerMethod": "POST"
        } );
    } );
</script>

<div id="container">
    <h1>All Clients</h1>

    <div id="body">
        <table id="example" class="display">
            <thead>
            <tr>
                <th>Name</th>
                <th>Surname</th>
                <th>Email</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</body>
</html>
like image 987
tsompanis Avatar asked Jul 24 '14 16:07

tsompanis


1 Answers

You need to specify the columns explicitly when using an array of objects instead of a two dimensional array.

"columns": [
                { "data": "id" },
                { "data": "name" }
              ]

You can find more info here

like image 170
kontramundo Avatar answered Sep 29 '22 10:09

kontramundo