Sorting dd.mm.YYYY(hh:ii:ss) format

Sorting dd.mm.YYYY(hh:ii:ss) format

Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

Hey :smile: i need to sort a table on my datatable by the dd.mm.YYYY(hh:ii:ss) format and don't find any solution.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    You can try the moment sorting plugin found here:
    https://datatables.net/plug-ins/sorting/

    Kevin

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    Thanks :)

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    i have tried with the code of "date-de" , but it didn´ t work .
    i need this form dd.mm.YYYY(hh:ii:ss).
    Can somebody help me :)

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    I would suggest using the Moment plug-in. It will support any date time format.

    Allan

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    Thanks Allan ,
    With wich Type should i declare my column if i use this plugin .
    I found a plugin for type"date" dd.mm.YYYY and it works .
    Sorry for my English and have a nice day :)

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    You would need to use the Moment documentation to determine exactly what values to use.

    Good to hear you have one working though.

    Allan

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    Hello again :)
    So i tried to understand the documentation but i didn´ t find a solution for my sorting problem . As i say i need to sort a column with this Format dd.mm.YYYY(hh:ii:ss) for exemple "04.01.2017 (11:59:27)" .
    Josh

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Minutes in Moment JS is represented by mm, while month is represented by MM.

    Have another look through the documentation I linked to above - I'm not sure why ii is being used for minutes in the above for example.

    Allan

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    thanks Allan :)
    i found a plugin for dd/mm/YYYY hh:ii:ss
    https://datatables.net/forums/discussion/26489/sorting-by-date-dd-mm-yyyy-hh-ii-ss-brazilian-format
    All what i need is to change the format in
    dd.mm.YYYY(hh:ii:ss) .
    Josh

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    Any help will be appreciated ;)
    josh

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    I would again recommend the Moment plug-in. The format you want is DD.MM.YYYY (HH:mm:ss), per the moment documentation that I've linked to already.

    Allan

  • NandraguNandragu Posts: 1Questions: 0Answers: 0
    edited April 2017

    Like allan said before, just include the moment plugin. ( https://momentjs.com/downloads/moment-with-locales.min.js ) and the datatables datetime plugin ( https://cdn.datatables.net/plug-ins/1.10.15/dataRender/datetime.js ).

    The columnDefs should look like:
    columnDefs: [{ 'targets': 7, 'render': $.fn.dataTable.render.moment( 'YYYY-MM-DD', 'DD.MM.YYYY hh:mm:ss', 'br' )}],

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    Thanks Allan and Nandragu .
    I do exactly like Nandragu says but now is the date not valid "Invalid date" at my table .

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    We'd need a test case showing the issue.

    Allan

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    I have datetimes like this :
    08.03.2017 (14:29:48)
    08.03.2017 (17:29:48)
    08.03.2017 (18:29:48)
    12.03.2017 (19:29:48)
    12.03.2017 (16:29:48)
    i included the first and the second plugin (Moment + datetime) and i give the same definition for my column
    columnDefs: [{ 'targets': 7, 'render': $.fn.dataTable.render.moment( 'YYYY-MM-DD', 'DD.MM.YYYY hh:mm:ss', 'br' )}],
    Sorry i dont have the right to show a "real" example but after adding plugins and writing definition i can t see the dates anymore (Invalid date ).
    Josh

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Can you simulate the problem using one of the options listed here:
    https://datatables.net/manual/tech-notes/10

    Kevin

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    It suggests that the value being rest in by Moment is something that it can't parse without some help.

    All you should need to do is add:

    $.fn.dataTable.moment( 'DD.MM.YYYY (HH:mm:ss)' );
    

    Before your DataTable initialisation. Remove the render stuff - you don't want that - you've already got a rendered data from what you said.

    If that doesn't help or work, please do create a test case. I've already linked to the Moment documentation and the sorting plug-in for it before.

    Allan

  • Rectec013Rectec013 Posts: 42Questions: 10Answers: 0

    Thanks a lot guys , i got it :)
    It works fine , i do exactly like Allan says and it works now ;)
    Josh

This discussion has been closed.