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 3615438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:22:24+00:00 2026-05-18T22:22:24+00:00

I have a table like this I’d like to sort : | Name |

  • 0

I have a table like this I’d like to sort :
| Name | Case |
| John | X-123/08 P|
| Bob | X-123/09 |
| Dylan | X-45/10 |

I want to sort the Case colum by case’s year then case’s number knowing that the format is always “X-(1 to 4 digits for case’s number)/(case’s year on 2 digits) (sometimes some text)”. It’s possible that after the year’s case I have some text but it shoud be ignored for sorting.

I am using tablesorter jQuery’s plugin and I am struggling to add a custom parser for this.

Thanks for your help !

EDIT : Here’s what I’m trying to do :

jQuery.tablesorter.addParser({ 
                // set a unique id 
                id: 'case', 
                is: function(s) { 
                    return false; 
                }, 
                format: function(s) { 
                    // format your data for normalization 
                    return s.replace(/^X-\d{1,4}\/(\d{2}).*$/, '$1') + ('000' + s.replace(/^X-(\d{1,4})\/\d{2}.*$/, '$1')).substr(-4);
                }, 
                // set type, either numeric or text 
                type: 'text'
            }); 

It’s working great until I encounter a case with 2 digits which is then ranked greater than a 3 digits one and I don’t understand why …
“X-458/09 P” is sorted smaller than “X-48/09” . I’ll try some debug to see what really happens.

EDIT 2 : Also tried the second answer :

jQuery.tablesorter.addParser({ 
                // set a unique id 
                id: 'case', 
                is: function(s) { 
                    return false; 
                }, 
                format: function(s) { 
                    var m = s.match(/X\-(\d+)\/(\d{2}).*$/);
                    var affaire = m[1];
                    var year = m[2];
                    return year + '000' + affaire;
                }, 
                // set type, either numeric or text 
                type: 'text'
            }); 

The result seems to be the same as the first one… I really can’t understand why it sucks. Why tablesorter thinks that 488 000 10 is smaller than 49 000 10 ?!

  • 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-05-18T22:22:25+00:00Added an answer on May 18, 2026 at 10:22 pm

    I think you can use:

    $.tablesorter.addParser({ 
        // set a unique id 
        id: 'case', 
        is: function(s) { 
            // return false so this parser is not auto detected 
            return false; 
        }, 
        format: function(s) { 
            // format your data for normalization 
            return s.replace(/^X-\d{1,4}\/(\d{2}).*$/, '$1') + ('000' + s.replace(/^X-(\d{1,4})\/\d{2}.*$/, '$1')).slice(-4);
        }, 
        // set type, either numeric or text 
        type: 'text'
    }); 
    

    EDIT:

    Maybe you already tried something like this with type: 'numeric'; I’m not sure, but this may fail because parseInt('09') === 0.

    EDIT 2:

    Changed to reflect sorting by year, then case number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.