Is it possible to use editor datetime field wireFormat with dayjs and not moment?

Is it possible to use editor datetime field wireFormat with dayjs and not moment?

aaron.dunigan.atleeaaron.dunigan.atlee Posts: 20Questions: 7Answers: 0

I have an app that already uses dayjs for all the date formatting, and I'm integrating DataTables Editor. For datetime fields, the editor doesn't seem to respect my setting of wireFormat: it just passes the date in the displayed format.

For example, this:

      {
          type: "datetime",
          def: function () { return new Date() },
          format: "M/D/YY",
          wireFormat: 'YYYY-MM-DD',
        }

sends the date to my backend in M/D/YY format.

If I add moment to the page then it works as expected and I get the date in YYYY-MM-DD format. But I'd rather not load both dayjs and moment.

The documentation for the datetime field doesn't mention dayjs, but my understanding is that it uses the DateTime extension, whose documentation says it integrates with dayjs.

I can provide a live test case if needed, but I can't access live.datatables.net right now, so maybe someone can answer the general question: should it be possible to set a wireFormat for a datetime field using dayjs and not moment? If so, what are the requirements or can you point me at an example?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    Answer ✓

    Hi,

    Thanks for your message. At the moment, no, sorry - only Moment.js is supported for that aspect. However, extending support to include dayjs (and Luxon) seems quite sensible. I will look into a way that Editor can use the date/time library assigned to DateTime rather than just assuming Moment.js. I'll target Editor 2.1 for that.

    Regards,
    Allan

  • aaron.dunigan.atleeaaron.dunigan.atlee Posts: 20Questions: 7Answers: 0

    Thanks @allan, that's good to know and I'll just live with loading both libraries for now. I look forward to that next update.

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    Just to say that this has indeed been committed now and will be in Editor 2.1 which will drop soon. It also also need an updated release of DateTime which will drop at the same time.

    Allan

  • aaron.dunigan.atleeaaron.dunigan.atlee Posts: 20Questions: 7Answers: 0

    Awesome, thanks for the heads up!

Sign In or Register to comment.