How to sort by prices ? (with "natural sorting" plugin for example)

How to sort by prices ? (with "natural sorting" plugin for example)

ValkyValky Posts: 5Questions: 0Answers: 0
edited April 2012 in DataTables 1.9
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.

Replies

  • ValkyValky Posts: 5Questions: 0Answers: 0
    edited April 2012
    I've also tried with the "natural sorting" plugin, but it doesn't seems to work, and I'm not sure to insert it correctly.
    You can see it here http://jsfiddle.net/DzaQe/1/

    Thanks for your help
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    > formattedNum

    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
  • ValkyValky Posts: 5Questions: 0Answers: 0
    Hi 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
This discussion has been closed.