Solved

jQuery Tablesorter plugin not working

Posted on 2011-09-30
6
1,609 Views
Last Modified: 2012-05-12
Hi,

I'm trying to implement jQuery tablesorter plugin in Coldfusion 9 pages. I can implement it fine on a page without any other .js file includes but when I try to use it in a .cfm that has other .js includes, it doesn't work. I make sure that jQuery is the first .js that is loaded and the css files are all in the right order. But the css does not fully load nor does the .js.

In firebug, I get the following error:

$("#myTable").tablesorter is not a function

I've been struggling with this for almost a day but nothing seems to work. Could someone who's implemented this and had similar issues point me in the right direction?
0
Comment
Question by:roger_v
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:ventaur
ID: 36893895
Are you making sure that your call to add table sorter to your table is after the DOM is loaded?

$(function() {
  $("#myTable").tablesorter;
});

Open in new window

0
 
LVL 6

Accepted Solution

by:
ventaur earned 500 total points
ID: 36893903
...also, include parentheses when calling tablesorter.

$(function() {
  $("#myTable").tablesorter();
});

Open in new window

0
 
LVL 1

Author Comment

by:roger_v
ID: 36894147
@ventaur:

Yes, I have document.ready before I call the tablesorter function. And I do have paren after tablesorter like so: tablesorter();

Here is my .cfm page that first includes another .cfm file that has all the css and .js files in it.

<!---test2.cfm--->
<head>
<cfinclude template="UI_Sorting.cfm">
  <script type="text/javascript">
        $(document).ready(function() {
            $("#myTable").tablesorter();
       });
 </script>
</head>

<body onload="SetPermissions();">


<!---UI_Sorting.cfm--->
<style type="text/css">
            @import url("../styles/tablesorter.css");
            @import url("../styles/jquery.tablesorter.pager.css");
            @import url("../styles/jquery-ui-1.8.14.custom.css");
            
</style>
<script src="../jquery/jquery-1.5.1.min.js" language="javascript"></script>
<script src="../jquery/jquery-ui-1.8.14.custom.min.js" language="javascript"></script>
<script src="../jquery/jquery.tablesorter.min.js" language="javascript"></script>
<script src="../jquery/jquery.tablesorter.pager-mod.js" language="javascript"></script>
<!---xxxx--->

Now, I do have another js function that is run on the onload of the body. Could that be a problem?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:roger_v
ID: 36894157
Nope, I removed the body onload js function but still get this error:

$("#myTable").tablesorter is not a function


I know that jquery is being loaded because I can invoke an alert box in the document.ready function and it works fine. It's just the table sorter function that is a problem.
0
 
LVL 1

Author Closing Comment

by:roger_v
ID: 36894209
Oops, I'm a total idiot on this! I was loading the jquery minified file twice! Thanks for your input though!
0
 
LVL 6

Expert Comment

by:ventaur
ID: 36894591
It happens. Glad you figured it out.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question