Sorting currency column

Sorting currency column

ripcurlksmripcurlksm Posts: 10Questions: 4Answers: 0

I am having problems sorting the "Amount" column... its sorting by the first integer instead of the entire value

http://lifescienceintelligence.com/EMT-Deals-Table/

Its sorting like this:
$1,000,000
$100,000,000
$2,000,000

Instead of this:
$1,000,000
$2,000,000
$100,000,000

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,928Questions: 1Answers: 10,153 Site admin
    edited September 2014

    You have specified:

        "columnDefs": [{
            "type": "numeric-comma",
            "targets": 3
        }],
    

    Remove that - it isn't needed in DataTables 1.10. DataTables will automatically detect and sort your numeric currency column.*

    Edit No it won't because you had string data in the column: "Undisclosed". You would need to create a sorting plug-in that will handle that. The formatted numbers plug-in might work - although it might require a change to add Undisclosed to the list of options that it treats as 0.

    Allan

  • ripcurlksmripcurlksm Posts: 10Questions: 4Answers: 0

    Thanks for taking a look Allan, how are you at regex to tweak the formatted numbers plugin for "Undisclosed"?

    Here is the current page:
    http://lifescienceintelligence.com/EMT-Deals-Table/index.html

    And here is the 'formatted numbers' plugin code im using:
    http://lifescienceintelligence.com/EMT-Deals-Table/extensions/formatted-numbers.js

  • allanallan Posts: 61,928Questions: 1Answers: 10,153 Site admin
    edited September 2014 Answer ✓

    A regex tweak not needed here - see the bit which has (a === "-" || a === "") - just add an extra condition which checks for Undisclosed there.

    Allan

  • ripcurlksmripcurlksm Posts: 10Questions: 4Answers: 0

    Thank you that worked!

This discussion has been closed.