jQuery: Chaining multiple functions gives Uncaught Typeerror

I'm attempting to chain multiple function calls in my script, but I keep getting Uncaught TypeError: $(...).tablesorter(...).tablesorterPager is not a function whenever I try to get it on my webpage.

The code in question is formatted like this:

function InitializeTableSorter() {
    var pagerOptions = {
        //object definitions in here
    }; 

    $("#transaction").tablesorter({
        //function stuff in here    
    }).tablesorterPager(pagerOptions);
}

I'm using the Tablesorter plugin here, which uses the tableSorter and tablesorterPager functions.

What went wrong here? Did I miss anything?

Answers:

Answer

Assuming you have the appropriate plugin files installed (in the appropriate order if order matters)

Uncaught TypeError: $(...).tablesorter(...).tablesorterPager is not a function

is usually encountered when there are conflicts between jQuery and other libraries. To stay out of trouble, call $.noConflict() and don't forget to run your jQuery code after the document is ready

$.noConflict();
jQuery(document).ready(function($){
  function InitializeTableSorter() {
    var pagerOptions = {
        //object definitions in here
    }; 

    $("#transaction").tablesorter({
        //function stuff in here    
    }).tablesorterPager(pagerOptions);
  }
});
Answer
jQuery(document).ready(function($){
    var pagerOptions = {
        //object definitions in here
    }; 

    $("#transaction").tablesorter({
        //function stuff in here    
    }).tablesorterPager(pagerOptions);
});

Use this method bottom of the page.

Answer

I think this is causing the error .tablesorterPager(pagerOptions);

Try with this:

function InitializeTableSorter() {
   var pagerOptions = {
       //object definitions in here
   }; 

   $("#transaction").tablesorter(pagerOptions);
}

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.