brackets-negative sorting plugin has issues with amounts of cents

brackets-negative sorting plugin has issues with amounts of cents

leslies61801leslies61801 Posts: 9Questions: 2Answers: 0

Hi,

I am implementing this plugin to solve sorting issues with amounts using brackets for negatives. The plugin does a great job in general. I have found a use case it has an issue:

It doesn't correctly sort to the 2nd decimal place always. For example, I am finding that amounts of just cents like 0.01 or 0.06 are stuck in with 0.00 values and not sorted properly. For example:

1.00
0.00
0.00
0.01
0.00
(1.00)

Has anyone else encountered this? Do you have any suggestions for fixing this?

Thanks!

This question has an accepted answers - jump to answer

Answers

  • leslies61801leslies61801 Posts: 9Questions: 2Answers: 0

    Forgot to mention that I am using DataTables 1.10.7

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @leslies61801 ,

    The two decimals are handled correctly, sp it's probably something to do with how you're dealing with those negative brackets.

    We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • leslies61801leslies61801 Posts: 9Questions: 2Answers: 0

    Hi Colin,

    I have created an example with most of our configuration and some real data. You can find my example at
    live.datatables.net/joqokeku/3/

    This example reproduces the issue I mentioned.

    Examples of the sort not handling amount less than 1 and greater than -1 well:
    * In the Current Month Expenses column, when you sort 0.09 is sorted in the of the 0.00 values instead of before or after them.
    * In the "Annual Planned Expense Budget" column that in a column of only 0.00 values there are two that are cents (0.01 and 0.05) and they are not sorted properly.
    * In the Encumbrances column values of 0.01 and 0.24 are being put within the 0.00 values by the sort.

    It could be an issue with my configuration, so I look forward to everyone's suggestions on how to fix this issue.

    Thanks,

    Leslie

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Hi Leslie,

    The negative brackets sorting uses parseInt() which is causing issues with your floating point data. Changing that allows it to work - I've also removed the column target for the negative brackets since it has a type detection plug-in so that wasn't required and can cause issues: http://live.datatables.net/joqokeku/4/edit .

    Allan

  • leslies61801leslies61801 Posts: 9Questions: 2Answers: 0

    Thank you, Allan!

    Your suggested changes to the plug-in resolved the issue! I appreciate your help with this.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @leslies61801 ,

    Just to say, the plugin has been updated with that change, so after the next release it will be part of the standard JS files so you won't need to have your customised version.

    Cheers,

    Colin

This discussion has been closed.