had a similar challenge with Data Tables a while ago. And this was with dates, formatted numbers and also with special characters in German. Your name sounds like you are from Scandinavia; might be relevant for you too I guess ...
You would need the following data tables plug ins to do all of this:
This one is for date time sorting: https://datatables.net/plug-ins/sorting/datetime-moment It also requires moment.js which I strongly recommend. https://momentjs.com/
This one is for international sorting when using special characters such as ä, ö ü etc.
https://datatables.net/plug-ins/sorting/intl
And this one is for formatted number sorting:
https://datatables.net/plug-ins/sorting/formatted-numbers
The examples below are about auto-detection of the respective fields depending on the user language.
Implementation examples:
So this is about formatted numbers. English format would be 1,000,000.99. German format is 1.000.000,99. It also takes care of empty fields.
//sorting of formatted numbers in English and German format
$.extend( $.fn.dataTable.ext.type.order, {
"formatted-num-pre": function ( a ) {
if (lang == 'de') {
a = a.toString().replace( /[\.]/g, "" );
a = a.toString().replace( /[\,]/g, "." );
} else {
a = a.toString().replace( /[\,]/g, "" );
}
a = a.toString().replace( /[^\d.-]/g, "" );
a = parseFloat(a);
if ( ! isNaN(a) ) {
return a;
} else {
//14 digit negative number to make sure empty cells always stay at the bottom / top
return -99999999999999;
}
},
"formatted-num-asc": function ( a, b ) {
return a - b;
},
"formatted-num-desc": function ( a, b ) {
return b - a;
}
} );
This is about international sorting:
//sorting:
//Use the phonebook variant of the German sort order,
//which expands umlauted vowels to character pairs: ä → ae, ö → oe, ü → ue.
if (lang === 'de') {
$.fn.dataTable.ext.order.intl("de-DE-u-co-phonebk");
} else {
$.fn.dataTable.ext.order.intl("en-GB");
}
And finally this is about date sorting:
//should be positioned after the number formatting to make sure
//date columns don't accidentally are assigned formatted-num
//set parms for date sorting using moment.js
$.fn.dataTable.moment( 'L', momentLocale );
the variable momentLocale in my example is either 'de' or 'en-gb'. The respective date formats are 10.11.2018 (German) or 10/11/2018 (English UK). (As opposed to 11/10/2018 in the American format which I think requires momentLocale to be 'en').