How to change date format ?

How to change date format ?

danygiacodanygiaco Posts: 10Questions: 4Answers: 0

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 !

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    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

  • danygiacodanygiaco Posts: 10Questions: 4Answers: 0

    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 ?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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 displayFormat and wireFormat respectively. They're described more on this page, with an example here.

    Colin

  • danygiacodanygiaco Posts: 10Questions: 4Answers: 0

    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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

This discussion has been closed.