“oCol 未定义”使用数据表和 jQuery Ui 对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6405429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"oCol is Undefined" Using Datatables and jQuery Ui Dialog
提问by Alejandro Echeverri
I have a form, for search a registry. This form, shows the info in a jQuery Dialog
, and, inside of the dialog, i am using Datatables
(Yes, inside of the dialog i have an entire table). I am generating the TR's and TD's dynamically with PHP, and then, PHP paste the string in the HTML.
But, when the dialog is shown i get this error:
我有一个表格,用于搜索注册表。这个表单显示了信息jQuery Dialog
,并且在对话框内部,我正在使用Datatables
(是的,在对话框内部我有一个完整的表格)。我正在用 PHP 动态生成 TR 和 TD,然后,PHP 将字符串粘贴到 HTML 中。但是,当显示对话框时,我收到此错误:
oCol is undefined: oCol.fnSetData( oData, val );
oCol 未定义: oCol.fnSetData( oData, val );
I'm trying it in Firefox and Chrome and it's the same thing. Also i've searched in http://www.datatables.net, and i discarded a 'malformed table'. I've no idea of what i'm doing wrong.
我正在 Firefox 和 Chrome 中尝试它,结果是一样的。我也在http://www.datatables.net 中搜索过,我丢弃了一个“格式错误的表格”。我不知道我做错了什么。
Can you Help me with this issue?
你能帮我解决这个问题吗?
This is my JS Block:
这是我的 JS 块:
<script type="text/javascript" language="javascript" src="lib/jQuery/jquery-1.6.1.js"></script>
<script type="text/javascript" language="javascript" src="lib/jQuery Ui/js/jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" language="javascript" src="lib/Datatables/DataTables-1.8.0/media/js/jquery.dataTables.js"></script>
<script type="text/javascript">
$(document).ready(function (){
$("#results").dialog({
title: "Results",
width: 900,
height: 500,
open: function(event, ui){
$("#tRes").dataTable({
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true
});
}
});
});
</script>
This is my Table (With the PHP Snippet):
这是我的表(带有 PHP 代码段):
<div id="results">
<table id="tRes">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>State</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<?php
echo $rows;
?>
</tbody>
</table>
</div>
Thanks in Advance.
提前致谢。
采纳答案by Nicola Peluchetti
Have you tried settings your Columns like this:
您是否尝试过像这样设置您的列:
$("#tRes").dataTable({
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"aoColumns": [
null,
null //put as many null values as your columns
]
});
If this still don't work, can you please post the generated html too? Another thing you could consider is initializing the table on document.ready and not only when you open the dialog, but i don't think that's the issue here.
如果这仍然不起作用,您能否也发布生成的html?您可以考虑的另一件事是在 document.ready 上初始化表格,而不仅仅是在您打开对话框时,但我认为这不是问题所在。
回答by thugsb
This may be happening because your table is not structured correctly. Make sure to have thead and tbody. I had this error, and once I added the thead and tbody it was gone. My settings were nothing like the settings in the other reply - I'm not sure why that one worked, as it didn't for me.
这可能是因为您的表格结构不正确。确保有 thead 和 tbody。我有这个错误,一旦我添加了 thead 和 tbody 它就消失了。我的设置与另一个回复中的设置完全不同 - 我不确定为什么那个设置有效,因为它对我不起作用。
table
thead
tr
th`s
tbody
tr`s
td`s
回答by G. I. Joe
The jQuery datatables plugin requires that the number of elementsin the <tbody>
tag match the number of <th>
elementsin the <thead>
tag of your table.
jQuery的数据表插件需要的元素数量的<tbody>
标签相匹配的数量<th>
元素在<thead>
你的表的标签。
回答by Soundar Kumar B R
$("#tRes").dataTable({ "bPaginate": true, "bLengthChange": true, "bFilter": true, "bSort": true, "bInfo": true, "bAutoWidth": true, });
$("#tRes").dataTable({ "bPaginate": true, "bLengthChange": true, "bFilter": true, "bSort": true, "bInfo": true, "bAutoWidth": true, });
Remove this code from your page and check syntax of setting values of text boxes then it will work fine.
从您的页面中删除此代码并检查设置文本框值的语法,然后它将正常工作。