Thank you both for taking the time to guide me in the right direction. I have
solved the problem, and you do need to create a new parser. The reason it
seemed to work when the page is loaded is because the textual representation
of a checked and un-checked checkbox is different. 

However, the parser is not as easy one would imagine. From the example that
tlphipps guided me to show how the format function takes one parameter 's'
containing the textual representation of a textbox. If you try to wrap this
(which I did) you do no get a reference to the actual checkbox and therefore
it doesn't work. 

If you go through the code and find the parser responsible for ip-addresses
you will notice that the format function actualy takes three parameters: s,
table, cell. If you wrap the cell and get the checkbox from it's child
elements we get the correct result. You still have to call
$("#myTable").trigger("update"); before sorting.

 $.tablesorter.addParser({ 
        // set a unique id 
        id: 'checkboxes', 
        is: function(s) { 
            // return false so this parser is not auto detected 
            return false; 
        }, 
        format: function(s,table,cell) { 
            // format your data for normalization
                        var checked = 
$(cell).children(":checkbox").get(0).checked;                     
            return  checked  ? 1 : 0; 
        }, 
        // set type, either numeric or text 
        type: 'numeric' 
    }); 

    $(function() { 
        $("#myTable").tablesorter({
                        debug:true,
            headers: { 
                1: { 
                    sorter:'checkboxes' 
                } 
            } 
        }); 
});
-- 
View this message in context: 
http://www.nabble.com/Tablesorter-2.0.3---Sorting-af-column-of-checkboxes-%28resorting%29-tp19308787s27240p19357296.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to