[英]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.