Date column having value like Aug 1,2017 sorting as string instead date
Date column having value like Aug 1,2017 sorting as string instead date
ovess
Posts: 15Questions: 1Answers: 0
I am populating data table using django .One of the column named Date consists values in the formatlike Aug 1,2017.
There is sorting issue as that date column sorting like string.
August 1,2017
July 10,2017
July 11,2017
This discussion has been closed.
Answers
Just use moment.js!
I only had to add one line of code to fix this:
https://momentjs.com/
You will probably need this:
This is the datatables plugin: https://datatables.net/plug-ins/sorting/datetime-moment
and of course you need to install moment.js. For the US I don't think you need to install additional locales. In case you do need to install the US locale a link like this should work:
your suggestion not worked. problems still persists
If you really have this format “August 1,2017“ with no blank between the comma and the year this might not be recognized. Just check the moment.js docs. I can reassure you moment and the plugin work ok.
sorting working fine in Chrome but not in Mozella Firefox
just tried mine in Firefox and it worked. Sorry, I am not a browser specialist ... and without seeing a single line of your code I am pretty sure that nobody is going to be able to help you out with this ...
@allan might be able to help you but you would need to provide your code and also run the data tables debugger on the table please: https://debug.datatables.net/
https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/en.js
getting 404 error
Well I said: "For the US I don't think you need to install additional locales. In case you do need to install the US locale a link like this should work:"
So this recommendation was just in case a locale file for the US was required. But it probably isn't! So why don't you try it without the locale file! (I can reassure you for languages other than US English you will need a locale file!).
Here you see all the available locale files. And yes, there is none for US English because it is the default language.
https://cdnjs.com/libraries/moment.js/
as evident in attached screenshot, date is starting from July 9,2017 instead of July 31,2017.
so this is the sorting issue i am having in Mozella Firefox
maybe this is caused by the 404 error? I would get rid of the error and try again ...
in another attached screenshot, it is shown that after August 7,2017, next date should be July 31,2017 but it is displaying July 10,2017.
kindly help.
Yes please, could you use the debugger as @rf1234 mentioned so we can see the setup.
Even better would be a link to the page showing the issue.
Allan
https://debug.datatables.net/elizih
kindly look into the attached html . sorting not working in Mozella
Your date strings are:
But the Moment documentation says that
LL
formatted strings should be like: September 4 1986 - i.e. no comma.So your date format doesn't match what it is being told to look for.
Allan
than what to do in my case to fix sorting problem in mozella
Found this in the moment.js source code:
Since US English is the default this is what moment uses if you don't specify a locale.
Just try this (without specifying a locale). It should still work in Chrome. If it doesn't work in Firefox then it is a browser or a moment.js problem which I don't think we can resolve here for you ...
i tried it
$.fn.dataTable.moment('MMMM D, YYYY' );
but nothing changes in mozella.
Since it works in Chrome you should get in touch with the Firefox support. I don't think it is a moment.js problem because for me it also works in Firefox. There must be something special in your application that causes the problem with Firefox ... Good luck with the Firefox support ...
Can you give me another debug trace with the latest version of your code please.
Allan
@allan https://debug.datatables.net/ofakelart
code is attached.
@ovess: 404 - Page not found ... try again pls
On Which page?
https://debug.datatables.net/ofakelart
That page.
https://debug.datatables.net/ajoloc
No tables! I guess you need to do this once you have the page with your table(s) opened in Firefox. Otherwise there are no table data. Please read the instructions carefully. I recommend to use the bookmarklet.
sorry. check the latest one
https://datatables.net/forums/discussion/43964
If the debugger shows 0 tables (like in the ajoloc trace) and you think you have created a DataTable, it normally means that there has been a Javascript error during the initialisation of the table.
Have a look at your browser's console.
Allan