Defining thousands and decimal in separate language file causes incorrect sorting
Defining thousands and decimal in separate language file causes incorrect sorting
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:
- In
initComplete
, how can I manually trigger a re-parse of the DOM to enable the correct sorting? - Could it be a feature request for DataTables to do this automatically when
thousands
ordecimal
has been defined in a file, fetched bylanguage.url
?
Thank you for your time.
Answers
https://stackoverflow.com/questions/53238318/html5-javascript-datatables-order-sort-of-columns/53238593#53238593
Has it all on sorting (more or less). Your number format is what most European countries have except for Switzerland and of course the UK.
Hi @andersolsen ,
This thread here might help too - it was recently discussing the same(ish) issue,
Cheers,
Colin