MarkE Posted February 16, 2019 Share Posted February 16, 2019 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? 1 Link to comment Share on other sites More sharing options...
elabx Posted February 16, 2019 Share Posted February 16, 2019 For what I can tell the tables use jquery table sorter for this task. Maybe you can check in their documentation how to restart the plugin with the format you require. Found this also, specific to date formats. 2 Link to comment Share on other sites More sharing options...
MarkE Posted February 16, 2019 Author Share Posted February 16, 2019 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? 1 Link to comment Share on other sites More sharing options...
kongondo Posted February 17, 2019 Share Posted February 17, 2019 (edited) 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 February 17, 2019 by kongondo 4 Link to comment Share on other sites More sharing options...
MarkE Posted February 17, 2019 Author Share Posted February 17, 2019 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). 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now