Sorting European Dates
Sorting European Dates
I have been through the forums and tried everything, but I can't seem to get the formatting and sorting of European dates to work correctly.
I am using Wordpress with the Divi theme and Tablepress plugins.
Optimally, I would like to use one table and format the dates differently depending on the locale.
I am using dates in the format "date.month.year" (dd.mm.yyyy). How does the raw data need to be formatted?
I have tried the following in the Page Editor:
<span>[table id=testtable datatables_locale="de_DE" /]</span>
Is there a way to set the locale globally or based on a parameter?
I have tried the following in the Table Editor JavaScript Function:
columnDefs: [{type: 'date-euro', targets: [1]}], order: [[ 1, 'asc' ]]
columnDefs: [{type: 'date', targets: [1]}], order: [[ 1, 'asc' ]]
columnDefs: [{type: 'date-de', targets: [1]}], order: [[ 1, 'asc' ]]
columnDefs: [{sType: 'date-euro', targets: [1]}], order: [[ 1, 'asc' ]]
I haven't figured out how to format the dates differently (e.g. dd.mm.yyyy, dd.mmm.yyyy, yyyy-mm-dd etc) using the same raw data.
Can you please help?
Answers
DataTables' built in date formatting is basically ISO8601 only (e.g. yyyy-mm-dd). However, with the moment plug-in you can sort just about any format you can think of.
There is a detailed description in the blog here.
Allan
Sorry, but I'm not a programmer and I'm trying to implement this all in Wordpress. This means that I don't have access to the HTML and can't simply include Javascript Code etc.
In Wordpress, I'm able to add the following JavaScript Functions:
order:[[1,'asc']],columnDefs:[{type:'date',targets:[1]}]
I also have the following Tag in the page:
[table id=testtable datatables_locale="de_DE" responsive=collapse responsive_breakpoint=phone datatables_paginate=false datatables_filter=false hide_columns="1" /]
I've tried the following code in the JavaScript Function, but it doesn't work.
order:[[1,'asc']],columnDefs:[{type:'datetime-moment',targets:[1]},{render: $.fn.dataTable.moment('L','de'),targets:[1]}]
Frankly, I'm not even sure where I would add the JavaScript files that would be needed (e.g. moment.js).
I'm afraid I'm not either. I know next to nothing about working with WordPress. You'd need to ask in a WordPress specific forum about how to include extra JS files and JS commands.
Remove that. The plug-in I linked to uses automatic type detection. Don't set the type at all as that would remove any automatic detection.
Use the
moment
plug-in before you initialise the DataTable, not inside it. Have a look at the example in the blog post to see how it should be done and then see if that can be replicated in WordPress.Allan