"e.handler.apply" is not a function in the jquery table sorter

In one of my applications, I am using JQUERY tablesorter. But when sorting with any of cloumns, I get below the error. Any idea why this is happening.

Error: "e.handler.apply" does not work in jquery.js

My code for using the table sorter is below.

$(".tablesorter") .tablesorter( { headers: { 0: { sorter: false}}, widgets: ['zebra'], fixedHeight: false }) .tablesorterPager({ container: $(".pager") }); $("#sortHeader").click( $(".tablesorter") .bind("sortStart",function(e, table) { $('.tablesorter').trigger('pageSet',0); }) ); 

But if I comment on code starting with β€œ$ (β€œ # sortHeader ”), clickβ€œ then it works fine. ”But I need this piece of code to satisfy my requirements.

Any thoughts on this.

+5
jquery tablesorter
source share
4 answers

You are missing the function() click block:

 $("#sortHeader").click(function(){ // <-----you need to have a callback function. $(".tablesorter").bind("sortStart",function(e, table){ $('.tablesorter').trigger('pageSet',0); }); }); // <---do a proper closing. 

The problem is in the code:

When you do:

 $("#sortHeader").click( 

without a callback function that always gives you an error in the jQuery library, as you learned Error : "e.handler.apply" is not function in Jquery.js

Since the .click() method is written, it needs a callback function to do something when you fire this event. therefore, in your code, jQuery believes that everything written in (...here...) is a callback for the compressed click event, and it cannot apply this callback.

+5
source share

As a matter of fact, you are trying to pass a parameter to a jQuery click function. More specifically, the return value of your bind call, which simply returns a jQuery object, which is not a function, so apply is undefined, and this leads to the error that you get.

You need to wrap what you wrote inside click() in the function declaration:

 $("#sortHeader").click( function(e) { //important! $(".tablesorter") .bind("sortStart",function(e, table) { $('.tablesorter').trigger('pageSet',0); }) }); //close it too 
+1
source share

As others have said, you must provide a function.

One way is to use existing code and wrap it with an anonymous function:

 $("#sortHeader").click( function() { $(".tablesorter") .bind("sortStart",function(e, table) { $('.tablesorter').trigger('pageSet',0) }) } }); 

Another way is to name this function. If you gave your function a name and are still having problems, make sure you pass the function name without parentheses.

 $("#sortHeader").click( myEventHanler ); // <-- function name without parens myEventHanler() { $(".tablesorter") .bind("sortStart",function(e, table) { $('.tablesorter').trigger('pageSet',0) }) } } 
+1
source share

I incorrectly placed the third parameter of the Underscore.js debounce function, which somehow caused the same error.

Poorly:

 $('#color_search_text').keyup(_.debounce(processSearch, MILLS_TO_IGNORE_SEARCH), true); 

Good:

 $('#color_search_text').keyup(_.debounce(processSearch, MILLS_TO_IGNORE_SEARCH, true)); 
0
source share

All Articles