Hours:minutes Ago sort

Hours:minutes Ago sort

hectorelgomezhectorelgomez Posts: 2Questions: 0Answers: 0

Hi Guys.

I have a table with time into Hours:minutes ago, it can be, ex: 5:12, 15:45, 25:50, 60:23, 150:34, 264:10, 500:15, 3500:16...

Is not numeric or date format, dataTables try to order as String.

I searched many formating types into http://datatables.net/plug-ins/sorting/ but nothing solve my problem.

Also I tryed use something like http://datatables.net/forums/discussion/2467/need-help-for-sorting-date-with-dd-mm-yyyy-format, using date, but normaly date is not my format.

It is possible sort my time format?

Thanks a lot.

Replies

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    The ultimate date / time sorting plug-in which uses Moment.js should be able to cope with this okay. Just configure it with the format you want to be able to sort.

    Allan

  • hectorelgomezhectorelgomez Posts: 2Questions: 0Answers: 0
    edited March 2015

    Hi Allan.

    May be I didn't explain me well.

    My hours format are not between 0-24 or 0-12, I have 0-Thousand or 0-hundred hours. By theese reason, the moments format (http://momentjs.com/docs/#/displaying/) not work for me.

    The moment.js allow there hours formats:
    H (0 1 ... 22 23),
    HH (00 01 ... 22 23),
    h: (1 2 ... 11 12),
    hh: (01 02 ... 11 12).

    Thanks.

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Thanks for the clarification. What you would need to do then is implement a custom sorting plug-in that will deformat the duration into a numeric representation that can be easily ordered. There are examples here.

    An alternative would be to use the orthogonal data options of DataTables.

    Allan

This discussion has been closed.