dokuwiki-plugin-struct icon indicating copy to clipboard operation
dokuwiki-plugin-struct copied to clipboard

Sorting date fields as normal text

Open ka2pink opened this issue 5 years ago • 4 comments

When aggregating tables the date fields are sorted as plain text.

ka2pink avatar Apr 10 '20 09:04 ka2pink

Thank you for opening this issue. CosmoCode is a software company in Berlin providing services for wiki, app and web development. As such we can't guarantee quick responses for issues opened on our Open Source projects. If you require certain features or bugs fixed, you can always hire us. Feel free to contact us at [email protected] for an offer.

auto-comment[bot] avatar Apr 10 '20 09:04 auto-comment[bot]

I sorted this out by making use of the sortablejs plugin, which supports sorting date formats (originally only US american date format mm/dd/yyyy). I did a simple hack to include my date format which is dd.mm.yyyy, as shown here: https://github.com/FyiurAmron/sortablejs/issues/47 Sortablejs sorts instantly via javascript without reloading the page. Only drawback is, that no URL parameters are written. And, additionally, some clean up of the header layout is needed for links and icons, when both sorting algorithms (struct and sortablejs) are used on the same header. I am working on it and I will post that later. Cheers!

Chris75forumname avatar Jul 12 '23 13:07 Chris75forumname

originally only US american date format mm/dd/yyyy

well, that's not exactly true - not only, but also. The default format for sorting dates is still the ISO norm. That's still something that should be fixed there, though :)

FyiurAmron avatar Jul 12 '23 15:07 FyiurAmron

Anyhow, to make sortablejs work with struct, some adjustments had to be made:

  1. Make sure, you are using the latest version of sortablejs, there were some important bug fixes in the recent past!
  2. In /dokuwiki/lib/plugins/sortablejs/screen.css update the first line of code, like so:
    div.sortable thead tr.row0 th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):not(.action):after {
    ...
  1. In /dokuwiki/lib/plugins/struct/script.js add the following code just BEFORE the last line of code with the last closing brackets:
// ****************************** compatibility: sortablejs + struct ******************************* 
        jQuery("div.sortable").each(function(i,$sortable){
           jQuery($sortable).find('div.structaggregation tr.row0 th:not(.sorttable_nosort):not(.action)').each(function(j,$th){
              if ( jQuery($th).length > 0 ) {
                 jQuery($th).text( jQuery($th).find('a').text() ).css('color','#286da8');
              }
           });
        });
// *************************************************************************************************

This nested loop loops through multiple tables of structaggregations or structaggregationeditors and looks for sortablejs table headers <th> and overwrites the struct <a> links in those headers, so they don't interfer with the sortablejs sorting links.

  1. Then, in the page make sure to use the syntax of nosort for each table header that is not supposed to be taken over by sortablejs, like so:
<sortable 1=nosort 2=date 3=nosort 4=numeric 5=nosort 6=nosort 7=nosort 8=nosort 9=nosort 10=nosort 11=nosort 12=nosort 13=nosort 14=nosort 15=nosort 16=nosort 17=nosort 18=nosort 19=nosort 20=nosort>
---- struct table ----
    ...
----
</sortable>

Notice: Index is based on (starts with) 1! In this example, the 2nd column is sorted as date and the 4th column is sorted as a numeric value via sortablejs! All the other table headers remain untouched by sortablejs and the above code (see 3.) and can be sorted by struct, as usual.

BTW: The implementation of type numeric in sortablejs is capable of cutting off units before and after numeric values. This makes it efficient to sort price and temperature values with units attached, which struct won't do. Very nice!

Chris75forumname avatar Jul 13 '23 16:07 Chris75forumname