【问题标题】:Datatables requested unknown parameter '0' for row 0数据表为第 0 行请求未知参数“0”
【发布时间】:2014-09-16 08:35:51
【问题描述】:

当我尝试从数据库中的客户表中获取数据时遇到了这个问题

DataTables 警告:表 id=example - 请求第 0 行的未知参数“0”。有关此错误的详细信息,请参阅http://datatables.net/tn/4

这是我在 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();
    }

}

这是我在 Codeigniter 中的观点(ps,我没有添加头文件,它太长了)

<!-- 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>

【问题讨论】:

    标签: codeigniter datatable datatables


    【解决方案1】:

    当使用对象数组而不是二维数组时,您需要明确指定列。

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

    You can find more info here

    【讨论】:

    • you need only specify the columns 是什么意思??在哪里添加它?在 js 或 server_processing.php 文件中?怎么加??一切都不清楚,请编辑答案并添加适当的详细信息。
    • 在使用对象数组而不是二维数组时,您需要明确指定列。你可以在这里找到更多信息:datatables.net/blog/2011-05-01
    • 这个答案不是描述性的
    猜你喜欢
    • 2019-01-28
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多