Trying to use the time-elapsed-dhms plugin, problems with sorting minutes

Trying to use the time-elapsed-dhms plugin, problems with sorting minutes

YungYung Posts: 3Questions: 1Answers: 0
edited January 2021 in Free community support

I have a column with time elapsed with a format like 5h 51, though it can go quite high, like 603h 59, 1036h 38, etc. The plugin works perfectly when sorting in a descending order (oldest to newest) but it only works for the hours in ascending order.

For example in descending order it'll correctly order
1744h 03, 1704h 56, 1704h 45, 1704h 05, 1657h 58

But in ascending order, it sorts like this:
5h 51, 603h 59, 603h 50, 603h 47, 653h 10...

It's like changing the sorting order only affects the hour and not how the minutes are sorted. Any ideas?

P.S. Removing the whitespace doesn't appear to affect anything.

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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

  • YungYung Posts: 3Questions: 1Answers: 0

    Ahh, yes I thought about making a fiddle, but it's quite a hassle with libraries....the live datatables tool is very useful.

    So here goes:
    http://live.datatables.net/lopunero/3/edit?html,js,output

    I've used similar values as I described and I am having the same issue. As you can see, the sort works for the hours, but the "middle" values stay at the exact same spot because the minute are overlooked.

    Any help would be appreciated

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    The problem is because on the line:

            return parseFloat(matches[1]) * multiplier;
    

    you're not factoring in the second part - you need to add those seconds to that calculation.

    Colin

  • YungYung Posts: 3Questions: 1Answers: 0
    edited January 2021

    Well it's not code I've written, but a plugin I've found on this website. Regardless, you pointed me in the right direction, here's my updated fiddle that works, if anyone is wondering. It'll only work for this exact format, but can be adjusted easily.
    http://live.datatables.net/vohihicu/1/edit?html,js,output

    Thanks for the help!

This discussion has been closed.