Site: Making pokemon tables' tier columns sort correctly (w/ code)

Hi all,

This is a relatively minor suggestion, but one that has always bugged me, so I spent some time fiddling around with jQuery today and made a fix.

My suggestion can be summed up with a couple of images. Currently, when you "sort by tier" on the Pokemon tables, you get this:


BL, BL2, LC, etc. Sort Descending starts you off in UU, then Uber. In both cases we're sorting alphabetically - not too hard to find the tier you want, but we can do better.

Here's how it looks when you sort by tier with the added code (Uber is all that's visible here, but if you scroll down it continues onto OU, BL, UU, BL2, etc.)


(Don't worry that the arrows are missing - that's just because I'm testing my code on a local copy, and I didn't save the images locally.)

The following is the code I used to achieve this effect. (It is a modified version of the existing javascript element that is directly after the table.)

Code:
    <script type="text/javascript">
        $.tablesorter.addParser({
        id: 'tier',
        is: function(s) {return false;},
        format: function(s) {
        return s.toLowerCase().replace(/ /g,'').replace(/\n/g,'')
        .replace(/^uber$/,  50)
        .replace(/^ou$/,    40)
        .replace(/^bl$/,    35)
        .replace(/^uu$/,    30)
        .replace(/^bl2$/,   25)
        .replace(/^ru$/,    20)
        .replace(/^nu$/,    10)
        .replace(/^lc$/,     5)
        .replace(/^limbo$/,  0)
        .replace(/^nfe$/,   -1);
        },
        type: 'numeric'
    });
        $("#pokemon_list4981250").tablesorter({
            widgets: ['zebra'],
            textExtraction: "complex",
            sortList: [[0,0], [1,0], [2,0], [3,0], [4,0], [5,0], [6,0], [7,0], [8,0], [9,0]],
            headers: {2: {sorter:'tier'}}
            })
    </script>
The modification uses builtin tablesorter functionality, and as such does not require any additional JS files or anything. It is fairly straightforward, and the integers are spaced out in case new tiers ever need be added.

To whoever handles the code, you can probably see the changes between the versions.
If not (or if you don't want to run a diff) here they are:
  • Add the first function ($.tablesorter.addParser) before tablesorter is called.
  • Add the line "headers: {2: {sorter:'tier'}}" to the tablesorter call, adding a comma at the end of the previous line.
  • Change [2,1] to [2,0] in the previous line so that the default order is Ascending (i.e., Ubers shows up at top on first click, NFE on second).

Thanks for your consideration,
~Zedadex
 

Redew

κακκῶ σεαυτόν
is a Site Content Manager Alumnusis a Forum Moderator Alumnusis a Contributor Alumnusis a Smogon Media Contributor Alumnus
Hey! This a really cool and useful idea! Currently, however, chaos and other programmers are working on a new dex/site design, so this is something included in it (I believe. If I am wrong, feel free to correct me!). If this is something that could be useful with the new dex, I think I'm going to tag Joim because he is a pretty techy guy with the forums. Thanks for taking the time to figure this out. :)
 
Cool Redew, thanks for the update! Looking forward to the new site design if it has this functionality :)
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top