render.moment : impossible to format a date using weekday

render.moment : impossible to format a date using weekday

XavlightXavlight Posts: 3Questions: 1Answers: 0

Hi,

I'm trying to format a date in my language (French) using 'render: $.fn.dataTable.render.moment' with 'ddd' to get the abbreviated day name.

I have a date in my column and I want to format it like this: 'S[week number] [shortened day] DD/MM'.

Code in datatable options :

...
columnDefs: [
    {
        targets: [4],
        render: $.fn.dataTable.render.moment('', '[S]ww ' + '<br>' + 'ddd DD/MM', 'fr')
    }
],
...

Example : 20/01/2022 - 2022-01-20
'S04
Thu 20/01'
The day is not translated.

I also tried to add (before datatable instance - $('#tableliste').DataTable( ):

$.extend(true, $.fn.dataTable.defaults, {
    language: {
        url: "https://cdn.datatables.net/plug-ins/1.13.2/i18n/fr-FR.json"
    }
});

I also tried to put in the options of datatable :

...
language: {
    url: "https://cdn.datatables.net/plug-ins/1.13.2/i18n/fr-FR.json"
},
...

Always the same result.
There's something I'm doing or something I haven't understood.

Thanks
Xav

Replies

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    The docs for the Datetime renderer describe the parameters to be provided. You are passing three parameters; from, to, locale. The from and to parameters need to match the supported tokens of the library (moment/luxon) library you are using. I don't believe '[S]ww ' + '<br>' + 'ddd DD/MM' is supported by either library.

    Sounds like you will need to use columns.render and use your preferred library to parse the column data to build and return the cell data the way you want it displayed.

    Your example 20/01/2022 - 2022-01-20 date is a bit confusing. What does the actual data look like? Please provide a simple test case that shows your original date format so we can offer more specific suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • XavlightXavlight Posts: 3Questions: 1Answers: 0

    Hi Kevin,

    Thanks for your reply.

    I found my problem.
    A another moment js library disrupted the proper functioning. (like a conflict, by without error)

    Origine date format : YYYY-MM-DD HH:mm:ss

    Only add moment library js with my local settings

    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/locale/fr.min.js" integrity="sha512-RAt2+PIRwJiyjWpzvvhKAG2LEdPpQhTgWfbEkFDCo8wC4rFYh5GQzJBVIFDswwaEDEYX16GEE/4fpeDNr7OIZw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    

    Now, it's right

    columnDefs: [
        {
            targets: 4,
            //Formatage :
            //S37
            //mer. 09/09
            render: $.fn.dataTable.render.moment('', '[S]ww ' + '<br>' + 'ddd DD/MM', 'fr')
        }
    ],
    

    with entry date : 2022-01-20 12:40:41
    render :
    S03
    jeu. 20/01

    That's right, with line feed.
    the formatting works correctly, by the 'moment js' library.

    Sorry for my poor english.

    Xav

Sign In or Register to comment.