0

I am using the jQuery DataTables library to style the tables on my website which is running Joomla 2.5. http://datatables.net/

The problem I am having is its not working, but it also isn't giving any sort of error in firebug either, so I have no trail to follow or anything.

The HTML / PHP of my table goes like this:

<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>

I am loading jQuery and the DataTables library and initializing it like this in the index.php of the template file :

<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>

The above should give me something along the lines of the following: Example DataTables Styled Table

jQuery is certainly working, as if I use the following it pops a box up as expected:

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

I have even tried jQuery No Conflict, by adding jQuery.noConflict(); before I call the function and still nothing, no errors, no working.


EDIT

If I change to the following I then get the following error:

<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>

This is the error I get in 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)
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Iain Simpson
  • 8,011
  • 13
  • 47
  • 66
  • You assign a class to the table `` but selecting it in JS as an id `$('#staff_table')`. Could this maybe fix it?
    – nuala Sep 05 '12 at 10:25
  • I did notice that a second ago and assigned the table an id or staff_table, but it didnt seem to solve anything. – Iain Simpson Sep 05 '12 at 10:31

3 Answers3

1

Your html for the table starts like this:

<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">

The h3 and p tags are not legal inside the table. Try moving them out of the table like:

<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">
Dietz
  • 578
  • 5
  • 14
  • Thanks, I tried your solution but am still having the same problem, also after making MY edit above ^^ I am now getting TypeError: oColumn is undefined also. – Iain Simpson Sep 05 '12 at 10:48
1

Datatables needs a <thead> and <tbody> tags to function properly

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
0

About onColumn error, try to call your datatable with parameters (according to your returned columns from the SQL query):

$('#staff_table').dataTable({ "aoColumns": [{ "mDataProp": "columnname1"},{ "mDataProp": "columnname2"},...]
});
Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82