currency sorting

currency sorting

dreagandreagan Posts: 1Questions: 1Answers: 0

I have an application, which I can't share with you since it is password protected unfortunately, that implements a datatable of prices.
I need to be able to sort these prices, which are in the following formatting: [€ 10,00]. At first I didn't give it any thought, but I soon oticed it didn't sort correcty. After some searching, I noticed datatables handled this as a string. So I implemented the currency sorting and currency auto-detect snippets. Which didn't do anything. It added a type to the types array, even though I couldn't see what type in my firebug debugger, but it did add one.
After that I saw the small print on the website that both of these were deprecated in the latest version of the library (1.10.0+). I was on 10.0, so just to make sure, I updated to the latest 1.10.3 and removed my snippets. Now that hasn't amounted to anything and I'm kind of stuck, since I don't really want to code currency sorting myself, seeing there are too many ways differences in formatting between currencies.

Anybody any tips or tricks to get this started?

Answers

  • allanallan Posts: 63,386Questions: 1Answers: 10,449 Site admin

    € 10,00

    Two issues there:

    1. It is not a number since there is a comma in it. I realise that a comma is used as a decimal separator, which is why there is a language.decimal option. DataTables follows the Javascript convention (and every other programming language I'm aware of) of using full stops as the default decimal separator. You would need to use the language.decimal option to specify your decimal separator (example and manual).
    2. There is a space in the string - DataTables will not detect the data as numeric (or specifically currency in this case) if there is a space.

    I think if you removed the space and used the language.decimal option it would work okay. If the space is required you would need to modify one of the available sorting plug-ins to suit your needs.

    Allan

This discussion has been closed.