jQuery Tabletools没有按预期工作

时间:2012-09-05 10:07:51

标签: jquery jquery-ui datatables html-table tabletools

我正在使用jQuery DataTables库来设置运行Joomla 2.5的网站上的表格。 http://datatables.net/

我遇到的问题是它无法正常工作,但它也没有在firebug中出现任何错误,所以我无法跟踪或任何事情。

我桌子的HTML / PHP是这样的:

<table class="staff_table">
<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>
<tr class="staff_table_head">
<td>Name</td>
<td>Job Title</td>
<td>Email Address</td>
</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>

我正在加载jQuery和DataTables库,并在模板文件的index.php中将其初始化为:

<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">             
$(document).ready(function() {
$('#staff_table').dataTable();
} );

 </script>

以上内容应该给我一些以下内容: Example DataTables Styled Table

jQuery当然有效,就像我使用以下内容一样,它按预期弹出一个框:

$(document).ready(function() {
   alert('hi');
});

我甚至尝试过jQuery No Conflict,在我调用函数之前添加jQuery.noConflict();仍然没有,没有错误,没有工作。


修改

如果我更改为以下内容,则会出现以下错误:

<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();
} );

 </script>

这是我在Firebug中遇到的错误:

TypeError: oColumn is undefined
initialize(b=Object { tweakInitial={...}, tweakSubsequent={...}, tweakSizes={...},     more...}, a=Object { options={...}, element=ul.menutop, rtl=false, more...}, c=span#span-    1346841479204301.daddy)fusion.js (line 8)
initialize()mootools-more.js (line 27)
b()mootools-core.js (line 140)
g()mootools-core.js (line 135)
initialize(o=span#span-1346841479204301.daddy, m=1)fusion.js (line 8)
forEach(i=function(), v=Object { options={...}, element=ul.menutop, rtl=false,     more...})mootools-core.js (line 39)
initialize(f="ul.menutop", k=Object { pill=0, effect="slide and fade", opacity=1,     more...})fusion.js (line 8)
initialize()mootools-more.js (line 27)
b()mootools-core.js (line 140)
g()mootools-core.js (line 135)
(?)()school-staff (line 77)
fireEvent(f=function())mootools-core.js (line 370)
forEach(i=function(), v=Window school-staff)mootools-core.js (line 39)
fireEvent(e="domready", c=[], b=undefined)mootools-core.js (line 370)
g()mootools-core.js (line 507)
[Break On This Error]   

...start({"margin-top":this.height,opacity:0}).chain(function(){if(this.childMenu.f...

fusion.js (line 8)

3 个答案:

答案 0 :(得分:1)

你的表格的html如下所示:

<table class="staff_table">
<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>
<tr class="staff_table_head">

表格中的h3和p标签不合法。尝试将它们移出表格,如:

<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">
<tr class="staff_table_head">

答案 1 :(得分:1)

数据表需要<thead><tbody>标记才能正常运行

答案 2 :(得分:0)

关于onColumn错误,请尝试使用参数调用您的数据表(根据SQL查询中返回的列):

$('#staff_table').dataTable({ "aoColumns": [{ "mDataProp": "columnname1"},{ "mDataProp": "columnname2"},...]
});