This has come up a couple of times before. According to my chat with Lobo today, not much is happening on this front. Since our client at Two Mice and a Strawberry has a need for this, we're diving in head first this week. Hopefully we'll have something that's worth contributing to core. Please comment below if you have any thoughts on the ideas presented here.
Our intent is to take the order_bys parameter that's mentioned passingly in the docs and build on it as follows.
The general idea
any column available for display is also available for sorting
additionally, columns defined in order_bys are also available for sorting
add as many sort columns as you wish (Correction: as many as you want, as long as you don't want more than 10), ascending or descending for each
any sort column can be marked as "create section header", in which case section headers with total counts are inserted at the top of each section
A couple of quick mockups show how this might look to the user:
1. Report criteria form showing "Order by Columns" section:
2. Report body showing output based on above critera:
It will be hard to get the section headers to play nicely with header-click table sorting; from a logical viewpoint it can be nonsensical, and from a technical viewpoint it can be pretty complex. We're considering either disabling header-click sorting entirely when section headers are used, or else removing them immediately when the table sort is changed by a header click.
We anticipate some headaches related to sorting, but at the moment this is more a fear of the unknown than any specific concern.
As I said, any feedback from the community would be really great. Since our client needs this pretty quickly, we'll probably come up with a solution that works for our immediate needs and then spend time afterward getting it generalized properly for core. I'm looking forward to your comments.