在我的jQuery网站表格中,我遇到了一个让Joomla Datatables库正确显示的问题。http://datatables.net
脚本对我的表格设置了一半的样式,然后放弃了(我改变了表格标题的颜色和文本的颜色,但没有datatables控件等)。
Firebug还抛出了以下错误:
TypeError: oColumn is undefined
在我的Joomla模板index.php中,我的<head>
中有以下内容
<script src="./datatables/js/jquery.js" type="text/javascript"></script>
<script src="./datatables/js/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('#staff_table').dataTable({
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true
} );
} );
</script>
HTML / PHP如下所示:
<h3>Members of Staff</h3>
<p>If you're looking for a member of staff at Tower Road Academy, you'll find their details here.</p>
<table class="staff_table" id="staff_table">
<tr class="staff_table_head">
<th>Name</th>
<th>Job Title</th>
<th>Email Address</th>
</tr>
<?php
$result = mysql_query("SELECT * FROM itsnb_chronoforms_data_addstaffmember");
while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>' . $row['staff_name'] . '</td><td>' . $row['staff_job'] . '</td><td><a href=mailto:"' . $row['staff_email'] . '">' . $row['staff_email'] . '</a>' . '</td>';
echo '</tr>';
}
?>
</table>
发布于 2012-09-05 20:09:05
在抛出错误之前,datatables对它接受的html非常严格。我添加了标签到我的html,现在它可以工作了,还请注意,你的头列必须有标签,而不是标签,因为这也会抛出一个错误。
html代码现在看起来如下所示:
<h3>Members of Staff</h3>
<p>If you're looking for a member of staff at Tower Road Academy, you'll find their details here.</p>
<table class="staff_table" id="staff_table">
<thead>
<tr class="staff_table_head">
<th>Name</th>
<th>Job Title</th>
<th>Email Address</th>
</tr>
</thead>
<?php
$result = mysql_query("SELECT * FROM itsnb_chronoforms_data_addstaffmember");
while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>' . $row['staff_name'] . '</td><td>' . $row['staff_job'] . '</td><td><a href=mailto:"' . $row['staff_email'] . '">' . $row['staff_email'] . '</a>' . '</td>';
echo '</tr>';
}
?>
</table>
调用jquery等如下所示:
<script src="./datatables/js/jquery.js" type="text/javascript"></script>
<script src="./datatables/js/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#staff_table').dataTable({
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true
} );
} );
</script>
发布于 2012-09-05 20:01:25
试试这个:
jQuery('#staff_table').dataTable({
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"aoColumns": [
null,
null //put as many null values as your columns
]
});
https://stackoverflow.com/questions/12280900
复制相似问题