How to ensure correct datetime parsing when using Moment.js
How to ensure correct datetime parsing when using Moment.js
I'm using editor to allow inline edition on a grid that has 3 columns displaying date and times. I have set each column's type to datetime and specified a format of MM-DD-YYYY h:mm a
as shown on this doc page: https://editor.datatables.net/reference/field/datetime
I'm using Moment.js to allow custom date formatting.
Problem comes when i edit a date (By selecting date and time from the timepicker): I get a warning message in the console coming from Moment.Js:
"Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info."
So, i know that Moment.js allows creating moment objects using String + Format, but where and when could i do that in Editor?
Is there a way to tell Editor how to parse the selected date and time using some Moment.js parsing feature?
Regards
This question has an accepted answers - jump to answer
Answers
Any one ?
Can you show me the configuration you are using for your Editor field and also a sample of the data being used to edit? That way I can attempt to recreate the issue locally.
Allan
I certainly can.
data:
The problem there is that the format in your data doesn't match the format that you are tell Moment the data is in.
What are the server-side libraries you are using to get the data? If it is the provided PHP or .NET libraries, I'd suggest using a get and set formatter like in the examples to have it modify the data that is sent to the client. It is that format that will be displayed in the DataTable (unless you have a renderer) and in the Editor fields.
Allan