data-order sorting difference between languages
data-order sorting difference between languages
Dear community,
we have a table which contains a column with costs and a custom currency called "NO-CUR" since we don't know which currency the customer used.
To have a locale independend sorting we are using the data-order
attribute and adding the computer representation of the number. eg: 123.456, 123.45 and so on.
In the english version this one works quite good but as soon as the customer changes to german, the numbers get treated differently. In that case 123.456 is higher than 123.45 because in germany we use a dot as thousand separator.
Is there any solution for it? We were quite sure, it worked before we swapped to DataTables 2.1. Were there any changes?
Thanks in advance and still, happy new year!
Pichutan
Answers
Hi Pichutan,
data-order
should always use a period for the decimal. The display (i.e. what is in the cell) should be localised, butdata-order
, since the end user doesn't see it, should be what the computer knows as a number.If that doesn't help, can you link to a page showing the issue so we can take a look and diagnose it further.
Allan
Happy New Year, Pichutan.
I have the exact same situation and I don't have to use "data-order". I auto-detect formatted-numbers in English or German. And then set the ordering. This works for all of my many data tables; no extra code required for any individual table.
In my case I only have two currencies: EUR and CHF, but you an add as many currencies as you like to the array on top. This code is executed BEFORE data table initialization. And yes: It could be written more elegantly ... this was one of the first things I wrote in Javascript.
German formatted number: 1.000.000,99
English formatted number: 1,000,000.99
Hello @allan ,
I prepared a fiddle for this problem. But actually I don't know how to add the language there, maybe you have a way to test it. It works perfectly fine in english but as soon as our users switch to german, the sorting is off.
https://jsfiddle.net/Pichutan/j032pwmc/8/
Since I can't give you access to our product, I made a screenshot of the same data I prepared for you in the fiddle, showing the problem. I know it is not perfect..
Happy new year, @rf1234 !
Thanks for your input I will check it out! What wonders me, it was definetly working before with the
data-order
attribute.Thank you for your help!
Pichutan
You'll need to clarify this for me please. Is it a browser or OS prefernce they change, or an option on your website?
If it is an option on your web-site, then presumably it would be possible to recreate an example with the not working state in JSFiddle? The example you linked to, appears to be working as expected?
Allan
Hey @allan,
They change a setting on our website, (browser independend) and depending on language they chose we load the language pack for DataTables. Does the language setting has an effect on the sorting?
Otherwise I will try to set up a small test thing, but it may be a lot of work, so maybe we can get around it
It shouldn't if you are using
data-order
, no.An example showing the broken state would be really useful. It is hard to debug something that is working as expected, as the current example appears to be
Allan
Hello @allan ,
We found the issue, it seems indeed to be an issue with the German language file.
The updated fiddle you can find here: https://jsfiddle.net/Pichutan/j032pwmc/11/
Pichutan
FYI: This issue is not just with German, but also with French.
I also tried with zh-HANT, it is working as expected though.
See this demo: https://jsfiddle.net/7dsnpmva/
Thanks for the example! The German and French language files are setting the
language.decimal
option and that is effect thedata-order
property, which I think is wrong. I'll look into what I can do about that.Allan
I've been looking into this, and if the translation file includes
language.decimal
then any data returned from the rendering function (which is what happens withdata-order
) will be passed through a transformer to convert the given decimal to a period decimal.Unfortunately, I don't think that is correct if
data-order
is specified, I think that should be the IEEE number and shouldn't be reformatted. The problem is that is fairly baked into DataTables (the transform happens after the renderer).The workaround is to override the language file's definitions:
https://jsfiddle.net/xut71w4p/
I need to have a proper think about how to handle this better - but that might be a DataTables 3 thing as I'm worried about any change here and backwards compatibility.
Allan
Not really because that will change the formatting of your data tables' footers like this for example:
In German this means we have 22.098 table entries while in reality we have 22,098 table entries which in German is: 22.098.
It should be looking like this instead:
When I switch to English my display changes like this:
Oh that's annoying! Well spotted. Yup, I need to come up with a better way to handle this.
The other workaround is to use comma decimal place numbers in
data-order
at the moment. That probably fixes it in stone since any change will be a backwards compatibility nightmare.allan