Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:59:02+00:00 2026-06-13T20:59:02+00:00

I am using this great version of jQuery Tablesorter: http://mottie.github.com/tablesorter/docs/index.html Everything is working well

  • 0

I am using this great version of jQuery Tablesorter: http://mottie.github.com/tablesorter/docs/index.html

Everything is working well but now I have this problem: in my table, I have one column which contains positions of basketball players. Therefore I want that column to be sorted logically like this: PG-SG-SF-PF-C.

I tried to create this custom sorting function – look at my script, column 2:

$(document).ready(function() { 

    $(".stats").tablesorter({
            sortInitialOrder: 'desc',
            sortRestart: true,
            // Enable use of the characterEquivalents reference 
            sortLocaleCompare: false, 
            // if false, upper case sorts BEFORE lower case 
            ignoreCase: true,
            headers: { 
                0: { 
                        sortInitialOrder: 'asc'
                }, 
                1: { 
                        sortInitialOrder: 'asc'
                },
                2: { 
                        textSorter: function(a, b){ 
                            var positions = {
                                "PG": 0,
                                "SG": 10,
                                "SF": 20,
                                "PF": 30,
                                "C": 40
                            };
                            return ((positions[a] < positions[b]) ? -1 : ((positions[a] > positions[b]) ? 1 : 0)); 
                        },
                        sortInitialOrder: 'asc'
                }
            }
        }
    ); 

});

However, the column is still being sorted alphabetically like a normal text string (C-PF-PG-SF-SG).

Where am I making a mistake? I am not particularly strong in Javascript so it is probably somewhere in the sorting function. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:59:03+00:00Added an answer on June 13, 2026 at 8:59 pm

    I figured it out by adding my own parser like it is shown in this question: Sorting Image and hyperlink columns in a table using JQuery Sorter plugin

    I will copy my script that works as I want it to work, hope it helps someone:

    $(document).ready(function() { 
    
        $.tablesorter.addParser({
                // set a unique id 
                id: 'positions',
                is: function(s) {
                        // return false so this parser is not auto detected 
                        return false;
                },
                format: function(s) {
                        // format your data for normalization 
                        return s.toLowerCase()
                                .replace("pg", "d")
                                .replace("sg", "h")
                                .replace("sf", "m")
                                .replace("pf", "r")
                                .replace("c", "v");
                },
                // set type, either numeric or text 
                type: 'text'
        });     
    
        $(".stats").tablesorter({
                sortInitialOrder: 'desc',
                sortRestart: true,
                headers: { 
                    0: { 
                            sortInitialOrder: 'asc'
                    }, 
                    1: { 
                            sortInitialOrder: 'asc'
                    },
                    2: { 
                            sorter: 'positions',
                            sortInitialOrder: 'asc'
                    }
                }
            }
        );
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this great plugin: http://www.sanisoft.com/blog/2009/06/22/jquery-auto-correct-plugin/ But it's not working with 1.6.2 or greater...
I'm using this ( http://www.j-download.com/demo/demo-j-dcontact.html ) form on my website. It works great but
Recently I started using https://github.com/crowdint/rails3-jquery-autocomplete It works great, but I was trying to set
I'm currently using the following jQuery plugin: jQuery OEmbed. This plugin works great in
I am using a script from this discussion: https://wordpress.stackexchange.com/a/14711/14649 It works great, but when
I am using the superfish menu from this example: http://users.tpg.com.au/j_birch/plugins/superfish/#examples (with Supersubs). It works
I am using this text editor for my windows forms application This works great
I have been using this code with great success to pull out the first
I'm using the Multimedia timer in Delphi and this works great for quite accurate
I am using carrierwave to upload images to amazon s3. This works great on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.