How to sort by prices ? (with "natural sorting" plugin for example)
How to sort by prices ? (with "natural sorting" plugin for example)
![Valky](https://secure.gravatar.com/avatar/a37500239e803ad19b482fd7eb700d1a/?default=https%3A%2F%2Fvanillicon.com%2Fa37500239e803ad19b482fd7eb700d1a_200.png&rating=g&size=120)
Hello,
How can we sort prices columns ?
Prices are formed like following (in PHP with number_format() ):
2 150 000 €
4 500 000 €
225 000 €
The same for surfaces like :
80 m²
200 m²
150 m²
I've tried the "formattedNum" plugin but at this time it doesn't works, it sorts like some Varchar and not numeric.
I guess that those are not understood like numbers by DataTables...
So... or how to format numbers into prices with DataTables ?
Thanks in advance.
How can we sort prices columns ?
Prices are formed like following (in PHP with number_format() ):
2 150 000 €
4 500 000 €
225 000 €
The same for surfaces like :
80 m²
200 m²
150 m²
I've tried the "formattedNum" plugin but at this time it doesn't works, it sorts like some Varchar and not numeric.
I guess that those are not understood like numbers by DataTables...
So... or how to format numbers into prices with DataTables ?
Thanks in advance.
This discussion has been closed.
Replies
You can see it here http://jsfiddle.net/DzaQe/1/
Thanks for your help
How did you use it? This should be the perfect plug-in for this use case. There is an example of how to do it here: http://datatables.net/release-datatables/examples/plug-ins/sorting_sType.html
Allan
Thanks for your answer.
My mistake was that : I thought sType will be automatic for each column, but we have to descibe each of them, like following :
[code]
"aoColumns": [{"sType": "formatted-num"},
{"sType": "formatted-num"},
{"sType": "formatted-num"},
{"sType": null},
{"sType": null},
....]
[/code]
Thanks a lot for your great work about DataTables, it's really useful !
A real simplification of SQL "ORDER BY" which is heavy and complicated with multiple entities and nested queries...
Sébastien