Sorting dd.mm.YYYY(hh:ii:ss) format
Sorting dd.mm.YYYY(hh:ii:ss) format
Rectec013
Posts: 42Questions: 10Answers: 0
Hey 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
This discussion has been closed.
Answers
You can try the moment sorting plugin found here:
https://datatables.net/plug-ins/sorting/
Kevin
Thanks
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
I would suggest using the Moment plug-in. It will support any date time format.
Allan
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
You would need to use the Moment documentation to determine exactly what values to use.
Good to hear you have one working though.
Allan
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
Minutes in Moment JS is represented by
mm
, while month is represented byMM
.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
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
Any help will be appreciated
josh
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
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' )}],
Thanks Allan and Nandragu .
I do exactly like Nandragu says but now is the date not valid "Invalid date" at my table .
We'd need a test case showing the issue.
Allan
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
Can you simulate the problem using one of the options listed here:
https://datatables.net/manual/tech-notes/10
Kevin
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:
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
Thanks a lot guys , i got it
It works fine , i do exactly like Allan says and it works now
Josh