Sort on a Currency Column

Sort on a Currency Column

boydwhiteboydwhite Posts: 3Questions: 0Answers: 0
edited February 2011 in General
I am really enjoying customizing DataTables for my project. So much so I donated. However, I am having a real hard time getting a column of currency values to sort. (Note: My column of currency values is NOT prefixed with a dollar sign or euro sign, they are just values with commas and decimals like this:
4,500.00
44,000.00
500,000.00
1,000,000.00
10,000.00 )
If have tried this
[code]{ "sSortDataType": "dom-text", "sType": "numeric"}[/code]
which does not work and I have tried the Formatted Numbers plugin to no avail. This seems like something that would be a very common column in a datagrid which could need sorting. I have looked for examples but have failed to find any. I have tried putting the Formatted Numbers code on my page and also in [code]jquery.dataTables.js[/code] to no avail. I am just not seeing how to get this to work. Help! (Another note, the column is clear of all extraneous HTML so it is a clean column).

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Thank you for the donation :-). I don't think you want sSortDataType (unless you are reading from an input element?). What you need here is sType with the formatted numbers plug-in: http://datatables.net/plug-ins/sorting#formatted_numbers (set sType to 'formatted-num').

    Regards,
    Allan
  • boydwhiteboydwhite Posts: 3Questions: 0Answers: 0
    Worked like a charm. Once I put the plug-in code in a separate JS file and then included it in my code the column now sorts perfectly. This DataTables is one swell piece of work.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Thanks very much :-). Good to hear you got it working.

    Regards,
    Allan
This discussion has been closed.