Datetime formatted incorrectly when 'editing' a row

Datetime formatted incorrectly when 'editing' a row

jonny.aa24jonny.aa24 Posts: 4Questions: 3Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

I have a table where I want the datetime format as YYYY-MM-DD HH:mm.

I've explicitly stated this in my code:

         { data: "tbl_mg_accounts.account_dt",         render: function (data, type, row) {
          return moment(new Date(data).toString()).format('YYYY-MM-DD HH:mm');
        } }

I have a button called 'duplicate', where I essentially select a row and the form keeps that data but I can edit it and resubmit as a new entry.

When I click this, the datetime format goes different, e.g. > Tue, 16 Nov 2021 09:30:00 GMT. This is despite specifying in my editor object:

                type:  'datetime',
                def:   function () { return new Date() },
                format: 'YYYY-MM-DD HH:mm'

When I click on that column when editing, and choose another datetime from the picker, the format corrects itself.
This same behaviour is for inline editing too.

How can I consistently have the same format throughout? The backend has YYYY-MM-DD HH:mm format so I'm not sure how Tue, 16 Nov 2021 09:30:00 GMT format appears. Is this a default of moment.js or from datatables side?

Answers

  • colincolin Posts: 14,303Questions: 1Answers: 2,431
    edited January 26

    There are two directions you can go, either the formatting on the client-side, or change when it's sent to and from the server. These examples here and here should get you going, the latter approach (and example) would probably be the best way to go, using displayFormat and wireFormat,

    Colin

Sign In or Register to comment.