【问题标题】:Requested unknown parameter '1' from the data source for row 0 in DataTables从数据源请求数据表中第 0 行的未知参数“1”
【发布时间】:2012-08-30 02:50:24
【问题描述】:

当我尝试将数据从我的数据库检索到表中时,我收到此错误:

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

下面是我使用的javascript

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

检索到的 JSON 数据:

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

下面是我的桌子:

<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 代码(点燃的数据表)

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

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

我正在使用 codeigniter 和 DataTables。

为什么会出现该错误以及如何将数据检索到表中?

【问题讨论】:

    标签: php codeigniter-2 jquery-datatables


    【解决方案1】:

    我也有同样的问题。问题就在这里:

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

    您有三个&lt;TH&gt;,但只有一个&lt;td&gt; 添加两个&lt;td&gt; 将修复您的错误。 还有一件事,如果没有数据可用,它会自动显示消息,你不需要显示消息。在这种情况下,你可以删除它,因为它会自动完成:

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

    为了自定义消息传递这个作为选项"sEmptyTable": "Loading data from server"

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

    【讨论】:

    • 我爱你。只是花了很长时间试图弄清楚这一点。
    • 我的代码使用了 colspan,希望 colspan 即使正确也不会导致这种情况!
    【解决方案2】:

    您正在使用 POST 方法获取数据。如果您按照datatables 提供的示例进行php,则使用GET 方法。我假设当您使用排序或搜索时,所有请求都是 GET。

    【讨论】:

    • 我已将 php 代码(点燃的数据表)添加到主帖中。
    【解决方案3】:

    一些可能有帮助的想法...

    1. 确保来自服务器的响应格式正确,带有正确的标头。例如 https://stackoverflow.com/a/4064468/661584 自己不确定点火器/php,但可能是个问题。

    2. 不确定 sColumns 参数本身是否正确,认为这是为了在客户端对 cols 重新排序...并且仅与 sName 一起使用,请参阅 http://datatables.net/usage/columns#sNamehttp://datatables.net/usage/server-side

    所以这可能会搞砸。

    1. 如果有其他问题,也许看看答案here... 可能会有所帮助。

    祝你好运

    【讨论】:

      【解决方案4】:

      我们遇到了类似的问题...

      但是,在你发疯之前 - 检查表中的数据。 在我们的例子中,我们的数据在填充表格的数据中使用了超链接和花引号——当从 CSV 文件上传数据时,这些引号和花引号被去掉了。 简短的故事是 IE 无法处理它,但 Chrome 和 Firefox 忽略了它。

      【讨论】:

        猜你喜欢
        • 2021-10-24
        • 2014-05-21
        • 2014-09-13
        • 1970-01-01
        • 2014-09-16
        • 1970-01-01
        • 2019-01-28
        • 1970-01-01
        • 2014-04-15
        相关资源
        最近更新 更多