How to change date format ?
How to change date format ?
Hello,
I am facing an issue concerning the date format within datatable.
I would like to display the data using the format "YYYY-MM-DD" (without hours, minutes and seconds).
Following the example given on this page: https://editor.datatables.net/examples/dates/formatting.html , I used the plug-in Moment.js in order to do it.
It works correctly for the input: when I enter a new data, the form displays the correct format.
Also, when I validate the new entry, the date is displayed using the wanted format.
However, once I refresh the page, the data is displayed in the default ISO 8601 format.
I have searched in the site and forum, but I did not succeed to fix this issue.
Have you got an idea of what I have made wrongly?
Thanks !
This discussion has been closed.
Answers
Datatables is responsible for displaying the table data. Sounds like you might need to use moment.js in
columns.render. While not exactly what you need this example shows how:http://live.datatables.net/vojowice/1/edit
Kevin
Thanks Kevin, it helps !
Now the date are correctly displayed.
I am facing another issue when I edit inline a date: the format of the date while I click on the cell is back to the default ISO 8601 format.
Is it related to the fact I use datetime field ?
There are two options you can use, one defines the format for display, the other defines the format to send to the server - these are
displayFormatandwireFormatrespectively. They're described more on this page, with an example here.Colin
Thanks for your answer Colin.
I used 'displayFormat' to correctly display the date.
When I tried to use 'wireFormat' I receive an error : "Invalid date" when I click on the cell to inline edit it.
And how can we manage the format display within the inline edit cell (when you click on it) ?
Thanks
Can you post the formats you're using pleas - both wire and display, and the JSON that you're getting? The inline edit would be the same as in the form.
Colin