简体   繁体   English

绑定的jQuery数据表给出错误“来自数据源的第0行的请求的未知参数'0'”

[英]binding jquery datatable gives error “Requested unknown parameter '0' from the data source for row 0”

i am creating json format for jquery datatable using jquery , but it gives error "DataTables warning (table id = 'tblDynamicModifierItems2'): Requested unknown parameter '0' from the data source for row 0" 我正在使用jquery为jquery数据表创建json格式,但它给出了错误“ DataTables警告(表ID ='tblDynamicModifierItems2'):从数据源请求的第0行的未知参数'0'”

my Html is 我的HTML是

 <table id="tblDynamicModifierItems" class="tblDynamicModifierItems table table-hover table-nomargin dataTable table-bordered dataTable-scroller dataTable-tools">
                                <tbody></tbody>
                            </table>

my Jquery code is 我的jQuery代码是

var aaData = [];
     var ModifierItemCode = "1";
            var Description = "10 cane rum"
            aaData.push({
                "ModifierItemCode": ModifierItemCode,
                "ModifierItem": Description,
                "Delete": "Delete"
            });

     var oTable = $("#tblDynamicModifierItems").dataTable({
                    "aaData": aaData,
                    "aoColumns": [{ "bVisible": false }, { "sTitle": "Description" }, null],

                });
                oTable.fnSort([[1, 'asc']]);

can anyOne help me solve this? 有人可以帮我解决这个问题吗?

You need to make the markup right. 您需要正确设置标记。 jQuery dataTables is very sensitive to that. jQuery dataTables对此非常敏感。 It is important to define the headers, <th> , so dataTables have a chance to know how many columns it should expect in each row of data. 定义标头<th>很重要,因此dataTables有机会知道在每行数据中应该有多少列。

<table id="tblDynamicModifierItems" class="tblDynamicModifierItems table table-hover table-nomargin dataTable table-bordered dataTable-scroller dataTable-tools">
    <thead>
       <tr>
           <th>ModifierItemCode</th>
           <th>ModifierItem</th>
           <th>Delete</th>
        </tr>
    </thead>    
    <tbody></tbody>
</table>

Also, you must tell dataTables which part of each aaData item that should correspond to which column : 另外,您必须告诉dataTables每个aaData项的哪一部分应与哪一列相对应:

var oTable = $("#tblDynamicModifierItems").dataTable({
     "aaData": aaData,
     "aoColumns": [
         { mDataProp : "ModifierItemCode" },
         { mDataProp : "ModifierItem" },         
         { mDataProp : "Delete" }
     ]     
});

your code in a demo -> http://jsfiddle.net/s9Lag6mc/ 您的代码在演示中-> http://jsfiddle.net/s9Lag6mc/

Regarding your "aoColumns": [{ "bVisible": false }, { "sTitle": "Description" }, null], I am not completely sure what you are trying to do, but if you want to hide the first column, just add bVisible: false to the first aoColumns item, and so on. 关于您的"aoColumns": [{ "bVisible": false }, { "sTitle": "Description" }, null],我不确定您要做什么,但是如果您要隐藏第一列,只需将bVisible: false添加到第一个aoColumns项,依此类推。


As for your fnCreatedRow problem : Think about it, you are inserting an object. 至于您的fnCreatedRow问题:考虑一下,您正在插入一个对象。 So instead of alert(aData[0]) (or whatever) simply 因此,而不是alert(aData[0]) (或其他)

alert(aData.ModifierItemCode);

forked fiddle -> http://jsfiddle.net/0aLys2d3/ 分叉的小提琴-> http://jsfiddle.net/0aLys2d3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从数据源请求行“ 0”的未知参数“ 1” - Requested unknown parameter '1' from the data source for row '0' 请求jQuery数据表中的第0行的未知参数1 - requested unknown parameter 1 for row 0 in jquery datatable 从数据源请求的行0问题的未知参数&#39;0&#39; - Requested unknown parameter '0' from the data source for row 0 issue 添加数据时的Jquery Datatable警告:请求的未知参数 - Jquery Datatable warning when adding data: Requested unknown parameter DataTables警告(表ID =“示例”):从数据源请求的第0行的未知参数“ 0” - DataTables warning (table id = 'example'): Requested unknown parameter '0' from the data source for row 0 在 DataTable 中显示数据时请求未知参数 - Requested unknown parameter, when Showing Data in DataTable 请求第0行的未知参数“ 5”(jquery数据表) - Requested unknown parameter '5' for row 0 (jquery datatables) jQuery Datatables请求行&#39;0&#39;列&#39;0&#39;的未知参数&#39;0&#39; - jQuery Datatables Requested unknown parameter '0' for row '0' column '0' 数据表错误:第0行第10列请求的未知参数&#39;10&#39;; 尝试将复选框添加到数据表时 - Datatables error: Requested unknown parameter '10' for row 0, column 10; when tried to add checkbox to the datatable 请求第1行的未知参数“ 0” - Requested unknown parameter '0' for row 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM