render.moment : impossible to format a date using weekday
render.moment : impossible to format a date using weekday
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
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
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
Now, it's right
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