DataTable.render.datetime('dd.MM.yyyy') not working

DataTable.render.datetime('dd.MM.yyyy') not working

SvenK69SvenK69 Posts: 2Questions: 1Answers: 0

Hi folks,
I want to format a ISO8601 date ('yyyy-MM-dd') to 'dd.MM.yyyy'.
If I use:
render: DataTable.render.date()
it changes the format to 'd.M.yyyy' like '3.6.2024', but I want '03.06.20024'.

I import luxon v3.4.4 with:
import { DateTime } from "luxon"
If I use:
render: DataTable.render.date('dd.MM.yyyy')
the result looks like this: "2024-06-03T00:00:00.000Z".
No error message.

Unfortunatelly in all the examples, it doesn't show, how exactly you have to import luxon.
Do I have to "initialize" luxon some how?
How do I have to import luxon, so that DataTable can use it?

I would be grateful for any tips!

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    As you are using ESM try:

    import * as luxon from 'luxon';
    
    DataTable.use(luxon);
    

    DataTables doesn't depend upon Luxon, so it needs to be told that if you want it to use Luxon, then do so. In a UMD (i.e. <script>) then it can check the global scope for Luxon, but that isn't relevant in ESM, hence the extra step.

    I'm going to work on the download builder to include this sort of information automatically soon.

    Allan

  • SvenK69SvenK69 Posts: 2Questions: 1Answers: 0

    Hi Allan,
    thanks for your answer!
    I tried, what you suggested, but unfortunatelly it didn't solve my problem.
    If I use:
    render: DataTable.render.date('dd.MM.yyyy')
    I still get an output like this: "2024-06-03T00:00:00.000Z".
    Still no error messages.
    Any other ideas?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hmmm - looks like there is something wrong with the Luxon library detection in DataTables when imported by ESM. Apologies for that.

    Fortunately it is easy to work around:

    DataTablesCore.use('luxon', luxon);
    

    Example.

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I think this commit will fix it :).

    Allan

Sign In or Register to comment.