Sorting date fields as normal text
When aggregating tables the date fields are sorted as plain text.
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.
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!
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 :)
Anyhow, to make sortablejs work with struct, some adjustments had to be made:
- Make sure, you are using the latest version of sortablejs, there were some important bug fixes in the recent past!
- In
/dokuwiki/lib/plugins/sortablejs/screen.cssupdate 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 {
...
- In
/dokuwiki/lib/plugins/struct/script.jsadd 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.
- Then, in the page make sure to use the syntax of
nosortfor 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!