Jump to content

MarkupAdminDataTable question re sorting dates


MarkE
 Share

Recommended Posts

Not sure how well documented MarkupAdminDataTable is, but I've managed to work out quite a bit and have found it very useful for custom admin pages.

One thing that has me stumped, however, is sorting dates. Obviously if the date is just rendered as a unix integer, it sorts fine but is not very meaningful. If I apply a datetime format, it sorts it as as string, which again is fine for 'Y/m/d' but no good for a more user-friendly format like 'd/m/Y' or 'relative'. I've tried applying class="datetime" to the items (which I spotted you can do by supplying an array of [item, class]) but that seems not to help.

Any ideas or pointers to more documentation?

  • Like 1
Link to comment
Share on other sites

1 hour ago, MarkE said:

Anyone any ideas how I put that over-ride into my site?

See the post below. You can prefix the actual visible date value with a hidden sortable value (e.g. yyyy-mm-dd).

 

Example code here. Follow the $dateSorter variable. The span with class="date-sorter" is hidden in the module's CSS file. The value in the span is the prefix. Sorting will be done based on it.

Edited by kongondo
  • Like 4
Link to comment
Share on other sites

Many thanks. Slightly adapted that. This works:

'<span style="display:none">' . $membership->modified . '</span>' . datetime('d/m/Y', $membership->modified)

with the MarkupAdminDataTable method setEncodeEntities(false)

BTW, I also tried 

'<span class="datetime">' . datetime('d/m/Y', $membership->modified) . '</span>',

which is what seems to be used in ListerPro (and works), but that didn't work in my module for some reason. Shame, because I would prefer not to have the concatenated formatted date after the unix integer as part of the sort key (although it shouldn't be a problem with the chosen format).

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...