Sort by Date Method?
-
Hey Tobias, quick question. How do you sort by date using mm/dd/yyyy?
I have a test page with an example of my table. If I sort by date, it starts using the month instead of the year.
I looked through the Extensions, but none of them seemed to address this. Apologies if I overlooked it.
Thanks!
-
Hi,
thanks for your question, and sorry for the trouble.
I’m not sure why the date sorting is not working here out of the box (as it should) but we can try to force it. For that, please add this to the “Custom Commands” text field on the table’s “Edit” screen:
"columnDefs": [ { "type": "date", "targets": [ 3 ] } ]Regards,
TobiasTobias, you are the freaking best! That custom command forced the dates to sort exactly as I wanted.
Just so I understand, what is the 3 referencing in the custom command?
Hi,
no problem, you are very welcome! 🙂 Good to hear that this helped!
The 3 is referring to the fourth column of the table (which has the dates, in your table). As counting starts with 0 in this code, column 4 is indicated by that 3.
Best wishes,
TobiasAhh, that makes perfect sense. Thanks again!
Hi,
sure! Always happy to help!
Best wishes,
TobiasHey Tobias, i have an similar Problem here. When u need the Website we have to gp in a privat chat, because ist just a dev site for now.
I created a table with 3 columns, Date | Description | Another text.
In the first column is the date in european format dd.mm.yyyy
Now i install your additional addon Datatables and fill custom commands with:
“columnDefs”: [ { “type”: “date”, “targets”: [ 0 ] } ]
Do i have to add an special command for european/german date ?
Because presently it isnt working.Hi,
thanks for your post, and sorry for the trouble.
To use the German/European format, you’ll just need a small change now:
"columnDefs": [ { "type": "date-eu", "targets": [ 0 ] } ]Regards,
TobiasWorks fine!
Thanks a lot Tobias.
Perhaps put it in ur FAQ or example, i searched ur whole site for it 😀Hi,
no problem, you are very welcome! 🙂 Good to hear that this helped!
Yes, I should probably add this to the Extensions’ web page.
Best wishes,
TobiasP.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!
Hi Tobias,
Can I jump in here with a similar query? Firstly, my date format is yyyy-mm-dd, and so far ‘date’ and ‘date-eu’ haven’t worked for me:
“columnDefs”: [ { “type”: “date-eu”, “targets”: [ 2 ] } ]
“columnDefs”: [ { “type”: “date”, “targets”: [ 2 ] } ]My dates are in column 3. I had a quick google reagrding my date format, and it looks like I’m using the Danish standard?! I’m guessing I need to use the suffix for this part of the world, but I don’t know what that is in your extension!
Awesome plugin by the way 🙂
Hi,
thanks for your post, and sorry for the trouble.
The format
yyyy-mm-ddcould actually work out of the box. And actually, we might not even need a date sorting algorithm, but can sort this as text strings – which actually is the default already…
Can you please post a link to the page with the table where this problem happens (without any of the “Custom Commands” from above), so that I can take a direct look? Thanks!Regards,
TobiasHi Tobias – ha, no need at all to apologise, thanks for your speedy response! Is there a way I can share the link privately?
Hi,
could you send it by email then? The address is in the main plugin file “tablepress.php”.
Regards,
Tobias
The topic ‘Sort by Date Method?’ is closed to new replies.