"e.handler.apply" is not a function in jquery table sorter
Asked Answered
I

4

5

In one of my application I am using JQUERY tablesorter.But while sorting with any of the cloumns I am getting below error. Any idea why this is happening.

Error : "e.handler.apply" is not function in Jquery.js

My code to use table sorter is as 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 am commenting the code which starts from "$("#sortHeader").click" then it is working fine. But I need that portion of code to meet my requirement.

Any thoughts on this.

Impatiens answered 18/6, 2014 at 10:18 Comment(3)
For starters, do not bind events inside events (except when the original events have been destroyed). That connects them multiple times!Provision
Also a sample with HTML (preferably in a JSFiddle) would be preferable on SO :)Provision
Related: Firefox only error with jQuery - handleObj.handler.apply is not a functionOdle
P
7

You are missing a function() callback block of click:

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

Issue in your code:

When you do :

$("#sortHeader").click(

without a callback function that will always gives you error in the jQuery library as you got to know Error : "e.handler.apply" is not function in Jquery.js

Because the way .click() method is written it needs a callback function to do something whenever you fire this event. so in your code jQuery thinks that whatever written in the (...here...) is a callback to the fired click event and it fails to apply that callback.

Philbrook answered 18/6, 2014 at 10:24 Comment(3)
Thanks Jai.... It worked..... I am new in Jquery and not much aware of what is happening inside Jquery file.Impatiens
@Philbrook way to go in terms of unsportsmanlike behaviour. I upvoted your answer which resulted in it getting accepted, but I answered first and you didn't vote at all, yet you expanded your answer with details that I included way ahead in mine.Pandolfi
@MDeSchaepmeester see i have not seen your answer when i was writing mine so that does not matter, yet if you feel that this is just i snatched an acceptance then its okay that is up to OP who can think which is the answer he/she can accept. Nonetheless for unsportsmanlike behaviour +1 to you too. Yet if OP feels you answered it better he/she can change the acceptance i don't mind.Philbrook
C
2

As others have said, you must provide a function.

One way is to take the existing code in question, and wrap it in an anonymous function:

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

The other way is to give this function a name. If you've given your function a name and are still having trouble, ensure that you have passed the function name without parentheses.

$("#sortHeader").click( myEventHanler );  // <-- function name without parens

myEventHanler() {
    $(".tablesorter")
    .bind("sortStart",function(e, table) 
        {
            $('.tablesorter').trigger('pageSet',0)
        })
    }
}
Credit answered 10/11, 2015 at 0:5 Comment(0)
P
1

As it stands, what you're trying to do is to pass a parameter to jQuery's click function. More specifically, the return value of your call to bind, which just returns a jQuery object, which is not a function, hence apply is undefined on it and this results in the error that you're getting.

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

$("#sortHeader").click( function(e) { //important!

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

    })

}); //close it too
Pandolfi answered 18/6, 2014 at 10:24 Comment(0)
O
0

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

Bad:

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

Good:

$('#color_search_text').keyup(_.debounce(processSearch,
        MILLS_TO_IGNORE_SEARCH, true));
Odle answered 4/2, 2015 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.