Jump to content
MarkE

MarkupAdminDataTable question re sorting dates

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

Share this post


Link to post
Share on other sites

Brill, thanks. Looks like mmddyyyy is hard-coded into the jquery tablesorter in wire.

I hacked that to ddmmyyyy and it works fine (until the next update 😞 )

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

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...