Defining thousands and decimal in separate language file causes incorrect sorting

Defining thousands and decimal in separate language file causes incorrect sorting

andersolsenandersolsen Posts: 1Questions: 1Answers: 0

Hi everyone.

I have a project where I format my cells according to the danish format, which is . for thousands and , for decimals (Example: 1.265,95 observations per month)

Since I use DataTables on multiple pages, I've created a language file for danish:

dataTables.danish.lang:

{
  "thousands": ".",
  "decimal": ",",
  "sProcessing":   "Henter...",
  "sLengthMenu":   "Vis _MENU_ linjer",
  "sZeroRecords":  "Ingen linjer at vise",
  "sInfo":         "Viser _START_ til _END_ af _TOTAL_ linjer",
  "sInfoEmpty":    "Viser 0 til 0 af 0 linjer",
  "sInfoFiltered": "(filtreret fra _MAX_ linjer)",
  "sInfoPostFix":  "",
  "sSearch":       "Søg i liste:",
  "sUrl":          "",
  "oPaginate": {
    "sFirst":    "Første",
    "sPrevious": "Forrige",
    "sNext":     "Næste",
    "sLast":     "Sidste"
  }
}

This file is loaded through AJAX like this:

$(document).ready( function () {
    $('#table').DataTable({
        paging: true,
        pageLength: 100,
        lengthChange: false,
        searching: true,
        info: false,
        order: [6, 'desc'],
        language: {
            url: "/dataTables.danish.lang"
        }
    });
} );

It results in 999 being sorted above 9.988

However, if I change the language block to the following:

language: {
    url: "/dataTables.danish.lang",
    thousands: ".",
    decimal: ","
}

Then the sorting works. This must mean that DataTables initially sorts the data using the default separators which is opposite (, for thousands, . for decimal) and then does not re-sort the data once the language file is loaded.

So my two questions are:

  1. In initComplete, how can I manually trigger a re-parse of the DOM to enable the correct sorting?
  2. Could it be a feature request for DataTables to do this automatically when thousands or decimal has been defined in a file, fetched by language.url ?

Thank you for your time.

Answers

This discussion has been closed.