Sort not working
Sort not working
I have a field that is sorting very strangely. The column contains a string made up of the city, state, and zip together. For some reason it is ignoring everything in the column but the numbers (which are at the end of the string).
columns:[ {"data":"city_st_zip"} ]
The sort is random ignoring the alphabet. It wasn't until I looked closely and noticed it was sorting on the numbers contained in the middle of the string. The sort looks like non-sense.
I have not been able to find any working solutions. :( When I come across something similar that worked for someone else it is always for a legacy version of Datatables. :(
Any help would be appreciated.
This question has an accepted answers - jump to answer
Answers
Here is the documentation on force datatables to use a certain data type.
http://datatables.net/reference/option/columns.type
If I take the space away before the zip code it starts working but is hard to read. If I try "& nbsp;" or a - (dash) before the zip it breaks again. This is a strange bug.
I suspect a work around would be sorting on a different value than the actual column text, but I can only find legacy examples of this. I can't find anything on recent docs. Surly they didn't remove this feature.
https://datatables.net/reference/option/columns.render
Thank you ThomD. I set it to a string. I guess it thought the name of the city was a unity of measurement like %$ or , .