DT Editor 2.0 doesn't sort numbers correctly
DT Editor 2.0 doesn't sort numbers correctly
Hi.
I am giving a try to move to Datatables Editor 2.0 from 1.7.4. I have read all of the release notes between these two versions but haven't seen anything about if number ordering have changed.
I have a cost column initialized like:
{ data: "cost", render: $.fn.dataTable.render.number( ',', '.', 2, '$ ' )},
There is no problem in the display but natural sorting ability is lost now. I mean the same column in version 1.7.4 is able to sort this column naturally like $2 comes before $10. But in Editor 2.0, now $2 comes after $10, $11...
How should I keep natural sorting? By the way custom rendering also has this problem. When I use this in a custom rendering function: if (type=='sort' || type=='type') return price;
, it still doesn't sort naturally but instead it sorts alphabetically.
Answers
The Editor doesn't perform sorting. That is a Datatables function. They are two separate applications.
This example, using
render: $.fn.dataTable.render.number( ',', '.', 2, '$ ' )
seems to sort correctly:http://live.datatables.net/kucozasa/1/edit
Please update the example or provide a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I have resolved the issue by adding
type: 'num-fmt'
to the column definition. Yet I still don't understand why I had to. The data in the database is pure float.Normally if that's needed it's because one of your cells has a non-numeric character in. But yep, glad you've got it working,
Colin
Thank you @colin for you time, but as I said, the data is pure float in the database. And I have now found out the reason why it broke and didn't work by default. If you point a JSON language file through
language
, numerical sorting breaks. So you need to definetype: 'num'
ortype: 'num-fmt'
for the columns that you need to have natural sorting.Odd, I'm not seeing it here - http://live.datatables.net/muhazunu/1/edit - and that's with a language file too. If you could reproduce the problem in my example, we'd be grateful, as we could apply a fix for it.
Colin
Yes, pretty odd. Your example looks perfectly fine to me. I will try to reproduce on a more basic setup; because I have heavy extensions in this one. But for the record, I had just ported the data from a working Datatables to the new version.
Excellent, thanks for that,
Colin