Client-side sort using STANDARDISTA-TABLE-SORTING.js

Posted on 2012-08-16
Last Modified: 2012-08-17
I am using the STANDARDISTA-TABLE-SORTING.js script.

I am having a problem with the sorting of number columns. If the columns include numbers all the same length (10, 31, 15, 20, 29), it sorts correctly. If the columns include numbers of varying lengths, it does not sort correctly. Some of the data is hard-code and the other data is generated from calculations of fields from the database. The following string is an example of an incorrect sort:
Question by:JLohman
    LVL 25

    Expert Comment

    Due to the comma in the number - it is sorting the values as text strings.

    Are they $ amounts?  If so - putting a $ sign at the start (e.g. $147,194) and it will sort them properly.

    If they are not $ amounts or you do not want a $ sign, then either remove the commas or a small change to the JavaScript file is required.

    Which do you want?

    Author Comment

    They are just numbers.

    If the javascript is modified, will it continue to work with other reports?

    I would prefer to be able to use commas.
    LVL 25

    Accepted Solution

    I know they are just numbers ... unfortunately the script was not programmed to recognise them as numbers.
    The attached version was modified by me to recognise numbers with commas as currency actually (it removes the $ and , to sort as a number).
    It should be fine with other reports, unless they also had numbers with commas - then their behaviour will change too ... for the better I would imagine.  BUT I have not extensively tested it NOR can I give any guarantees.

    Author Closing Comment

    Works perfectly!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Grouping within groups: SQL 5 29
    Oracle Pivot 2 21
    Php Sql Query 7 19
    Search box won't work. 22 19
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now