djangopackages-zz / djangopackages

Django Packages - a place to review Django apps, frameworks, and projects.
http://djangopackages.com
MIT License
53 stars 40 forks source link

Sorting by "# Using This" is incorrect #18

Closed chrishas35 closed 13 years ago

chrishas35 commented 14 years ago

Appears to be doing a string sort, rather than actual integer value.

http://www.djangopackages.com/categories/apps/ shows order as 9, 7, 5, 4, 43, 40, 3...

ipmb commented 14 years ago

I don't have time to setup the project right now, but I think this should do the trick. Replace: $(document).ready(function() { $("#home-packages").tablesorter(); } );

with the following:

// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'usageCount', 
    is: function(s) { 
        // return false so this parser is not auto detected 
        return false; 
    }, 
    format: function(s) { 
        // match number in span.usage-count
        return s.match(/<span class="usage-count">(\d+)/)[1];
    }, 
    // set type, either numeric or text 
    type: 'numeric' 
}); 

$(document).ready(function() { 
    $("#home-packages").tablesorter({ 
        headers: { 
            0: { 
                sorter:'usageCount' 
            } 
        } 
    }); 
});