Hi,
you are correct. Sorting values with spaces (just like currency values) needs some “special treatment”. This is because the JavaScript code does not know that the cell content is number when it contains spaces and then believes it is a string.
From the DataTables website I found some code which should tell the plugin how to sort such values anyway. I built a WP-Table Reloaded Extension from that, which you can get here: http://tobias.baethge.com/download/plugins/additional/wp-table-reloaded-currency-sorting.zip
(Don’t let the name fool you. The code is intended for currency values but works for your numbers as well.)
Please install that as a regular WordPress plugin and activate it.
After that, you will need to add a command to the “Custom Commands” textfield in the “DataTables JavaScript Features” section on the “Edit” screen of your table:
"aoColumnDefs": [ { "sType": "currency_sorting", "aTargets": [ "column-1", "column-3" ] } ]
That example would make the columns 1 and 3 treated with this code, so just change that as necessary.
Regards,
Tobias
Thank you Tobias – it looks great! : )
I have one more question according to this fix, let’s say that I have number-valued column and some of the fields are like “no data” and it’s signed by dash and it looks like that:
12 200 191
15 243 512
-
243 512
15 666 512
-
14 243 512
It looks like sorting can’t handle these dashes – is there some special character, which should I use for this purpose?
I tried with no character at all instead of dash and it works weird too : /
Thank you!
Hi,
it should actually work with an empty cell, as that is treated as 0 as far as I know…
Regards,
Tobias
Hi,
it’ actually not working with empty cells : ( Works fine only when all cells are numbers.
Thank you!
Hi,
mmh, okay… It is possible that the empty cells only work if the default sorting is used. I guess, you’ll have to decide: Either use only numbers without spaces, or don’t include rows without a value…
Regards,
Tobias
Ok, i’ll do it that way : ) thanks!
Hi,
ok 🙂 Sorry for not having a solution that works with both these things.
Best wishes,
Tobias