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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:21:31+00:00 2026-06-06T23:21:31+00:00

I am using jquery.datatables to show numbers in datatables columns. Numbers are formatted to

  • 0

I am using jquery.datatables to show numbers in datatables columns. Numbers are formatted to have spaces in between thousands unit (like 123 456 789). Unfortunately, this number formatting provoques a string sorting instead of a number sorting (see the screenshot at the end of this question).

I have identified that:

  • function _fnSort(oSettings, bApplyClasses) { is the core function for sorting.
  • In this function, the dynamic function sorting approach is used (the one executed if if (!window.runtime) { is true)
  • The string sorting functions used are the two following functions.

    /*
    * text sorting
    */
    "string-asc": function(a, b) {
        var x = a.toLowerCase();
        var y = b.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    },
    
    "string-desc": function(a, b) {
        var x = a.toLowerCase();
        var y = b.toLowerCase();
        return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    },
    

My knowledge in javascript is pretty poor, what would be the best approach here?

  1. Tweak the string sorting function to detect the number thousands formatted case, and do the comparison (I guess this would be pretty slow on large data set).
  2. Provide a numerical sorting function dedicated for number thousands formatted? In that case
    • how would you code that?
    • how could I indicate to the core sorting function, to use this special numerical sorting function?

Here is what the sorting look like by now:

enter image description here

  • 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-06T23:21:32+00:00Added an answer on June 6, 2026 at 11:21 pm

    To sort this kind of values, you can use this sort function :

    var sortFunction=function(a, b)​{
        var ia = parseInt(a.split(' ').join(''), 10);
        var ib = parseInt(b.split(' ').join(''), 10);
        return ia-ib;
    };
    

    Test :

    var data = ['3 333', '100 333', '22 000', '1 333'];
    console.log(data.sort(sortFunction));
    

    With a reasonable number of values, this will be fast enough. You shouldn’t try to enrich the data if you don’t detect performance problems.

    EDIT :

    In fact, the documentation proposes an appropriate (similar) sorting function :

    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
        "formatted_numbers-pre": function ( a ) {
            a = (a==="-") ? 0 : a.replace( /[^\d\-\.]/g, "" );
            return parseFloat( a );
        },
    
        "formatted_numbers-asc": function ( a, b ) {
            return a - b;
        },
    
        "formatted_numbers-desc": function ( a, b ) {
            return b - a;
        }
    } );
    

    After having added this extension, you just have to set the sType of your column.

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

Sidebar

Related Questions

I am using the jQuery DataTables plugin. I would like to move the search
I have started using the DataTables plugin (v1.6.2) for jQuery (v1.4.2), and I would
I have an ASP.NET MVC 3 app and I'm using jQuery DataTables as grid.
I am using Datatables Collapsible/Expandable Grouping. http://jquery-datatables-row-grouping.googlecode.com/svn/trunk/collapsibleGroups.html I have configured it so that all
I'm using datatables plugin for jquery to show my data on the page. I
I am using jQuery datatables in a dynamic PHP site. I have a page
I have been using the DataTables plugin for jQuery (http://www.datatables.net) to search, sort and
I have a datatable I'm using which has 5 columns ( http://datatables.net/ ) The
I am using the datatables jquery plugin. I would like to pull just the
I'm building a simple search table (eventually using jquery Datatables) for our knowledgebase. I'm

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.