Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Formatting numbers using DataTables breaks sorting

I have a tables that I am trying to sort, the problem is that when I add locales to the numbers, it breaks sorting, it sorts as it were strings.

I followed this answer and I modified without having to use regex, but then it begins sorting as it were strings and no longer numbers, for instance

1
1.200
2
$(document).ready(function () {
    $('.my_table').DataTable({
        "bProcessing": true,
        "bPaginate": true,
        "bDestroy": true,
        "bShowPollInfo": false,
        "iDisplayLength": 20,
        "aLengthMenu": [[20, 40, -1], [20, 40, "_all"]],
        "sScrollX": "100%",
        "aoColumns": [
            { "sWidth": "160px", "sClass": "nowrap" },
        ],
        "aoColumnDefs": [
            {
               "mRender": function (data, type, row) {
                   return formatNumbers(data);
               },
               "aTargets": [1, 2]
            },
        ],
    });
});
function formatNumbers(val) {
    return parseInt(val).toLocaleString("de-DE");
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change the "aoColumnDefs" part to this

"aoColumnDefs": [
    {
       "mRender": function (data, type, row) {
            if( type === 'display' ){
                return formatNumbers(data); // only format the data for display
            }else{
                return data; // the default data should be used for sorting
            }
       },
       "aTargets": [1, 2]
    },
],
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!