Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery tablesorter and select all checkbox in table header

I have a table with a "select all" checkbox as the first header column and some simple code to select all checkboxes on the page when the header checkbox is clicked.

$('#CheckAll').bind('click',function() {
        var checked = $(this).attr('checked');
        $('input').attr('checked', checked);
    });

the code runs fine, but as soon as I bind tablesorter to the table the click event on #CheckAll no longer seems to fire:

$('#ResultsTable').tablesorter( headers: { 0: { sorter: false} });

Any ideas?

like image 258
Justin Avatar asked Aug 10 '09 17:08

Justin


2 Answers

It's quite possible tablesorter is destroying/recreating the original Dom element. You can either bind AFTER your call to tablesorter, or else you might try "live" instead of "bind":

$('#CheckAll').live('click',function() {
        var checked = $(this).attr('checked');
        $('input').attr('checked', checked);
    });
like image 56
aquinas Avatar answered Oct 18 '22 12:10

aquinas


You almost got it!. Try this one:

 $("#tablesorter").tablesorter({headers:{0:{sorter:false}}}); 
like image 33
user974118 Avatar answered Oct 18 '22 10:10

user974118