Sort with thousands separador doesn’t work
Sort with thousands separador doesn’t work
Durovni
Posts: 3Questions: 0Answers: 0
Hi folks,
I haver to work with decimals (comma) and thousands ( dot) separators. I set the datatable to work with it And it works fine. But it does not work when the Number is smaller the 1000 and of course does not have thousand separators.
Numbers are
1.234,13
876,40
32,79
1.004,23
When I click column head to sort it Goes like this
1.004,23
1.234,13
32,79
876,40
Can anyone help?
Thanks in avance
Moises
This discussion has been closed.
Replies
Hi Moises,
Your example data appears to work okay here. Perhaps you can link to a test case showing the issue (per the forum rules)?
Thanks,
Allan
Hi Allan,
Thank you very much for your answer, by your exemple I could find what I was doing wrong.
There was a mistake in my js file, decimal and thousands were surrounded by " ".. When I fix it per you code it worked beautifuly.
The wrong code
$('#example').DataTable( {
language: {
"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Portuguese-Brasil.json",
"decimal": ",",
"thousands": "."
} );
Many thanks
PS. How do I mark this as answered?
You don't - this thread was started with the "New Discussion" button rather than "Ask a Question". Just seeing your reply above let's me know its answered now.
Good to hear you've got it working now!
Allan
New here, @allan Could you help check this
Column 3 isn't consistent when sorting. It just doesn't go from high to low.
Column 8 is also a tricky data and just don't know if there is any way to that too.
Will appreciate any help.
₦
isn't a currency symbol that DataTables picks up by default I'm afraid - it would need either a tweak in DataTables to add it, or use the formatting numbers plug-in.Alternatively use orthogonal data which is what I would recommend, assuming you can control the HTML output?
Orthogonal data would also work for the final column in the table since it could have a numerical value, while the display is still the human readable output.
Allan
I'm using v1.10+, shouldn't format numbers be built in?
Wouldn't mind if you could help edit the code to solve column 3 issue.
Column 8 seems like a complicated one.
Hi @a_j ,
here's column 3 working. Yep, column 8 is bespoke, you would need to do something like this - take the "billions" for example, and multiply up the number that you return.
Cheers,
Colin
@colin Thanks alot, really appreciate.
Guess i would just disable sort for the 8th column for now.
You could use this plug-in as inspiration for sorting human language numbers if you can't do orthogonal ordering.
No. That plug-in is very aggressive. It will strip out everything that isn't a number, so it has to be targeted at specific columns. For that reason it remains a plug-in.
Allan
@allan is there a way to target span attribute instead of the span content?
I could make the JS generate a non-formatted number string into an attribute.
E.G
<span rel="tooltip" class="marketcapXRP" data-number="1200000.00">₦1.2 Million</span>
For the above code, how will i tell datatable to sort span attribute (data-number) instead of span content?
Sorry, never knew there was data-order attribute option that can be added to the <td> for sorting.
The issue is now solved.
Thanks