类型错误:使用 jQuery Datatables 库时未定义 oColumn

2022-08-30 21:58:41

我在让jQuery Datatables库在我的Joomla网站表上正确显示时遇到问题。http://datatables.net

脚本是我的表格的一半样式,然后放弃(我得到了表格标题颜色的变化和文本颜色,但没有数据表控件等)。

Firebug 还抛出了以下错误:

 TypeError: oColumn is undefined

在我的Joomla模板索引中.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>

答案 1

要使数据表正常工作,必须使用适当的和标记构造表。<thead><tbody>

HTML中的所有数据表都需要一个格式良好的数据表(即有效的HTML),其中包含标题(由HTML标记定义)和正文(标记)<TABLE><THEAD><TBODY>

数据表文档


答案 2

对它进行了排序!,事实证明,数据表在抛出错误之前对它接受的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>

推荐