Problem:
Views Grouping Field feature doesn't work well in combination with Sortable
table fields, especially with lots of matches and pagination enabled. Certain fields being click sorted counteracts the grouping effect--especially when views return lots of matches which are paginated. I needed a way to ensure I can keep records grouped and still offer my users click sorting options by table field. Views Table Option: "Override normal sorting if click sorting is used" * When CHECKED and user has initiated CLICK SORT, click sort field(s) are PREPENDED to the SORT BY clause (NOT REPLACING IT ENTIRELY!) thus taking priority while still preserving the potentially multiple base view Sort rules specified by the author of the view. This helps with elaborate views that may contain many fields. * When CHECKED and user has NOT initiated CLICK SORT (meaning no sorting is applied except any Sort rules specified in the view), view sort rules are used (no change from current functionality here; just included for the sake of completeness of my bullet list matrix) * When UNCHECKED, and user has initiated CLICK SORT, click sort field(s) are APPENDED to the SORT BY clause (NOT PREPENDING IT!!) this taking secondary position while still preserving view author's sort rules. * When UNCHECKED, and user has NOT initiated CLICK SORT--same as second bullet point above--just use view sort rules; no proposed change there. This enables you to do something like this with your views: Say you are displaying a view listing fields from job nodes as well as fields from related user content profile nodes. You want the view to group both node types (profiles and jobs) by the node user name, sorting so the profile node displays first and then all job nodes display second beneath the profile and then further sorted so job nodes are displayed in the order of last modified first. While some manipulation to the view theme markup is necessary to eliminate repeating of the profile node for every job node (instead only displaying the profile node once the first time and then only the fields from the job node for the remaining times until a new group is encountered), it is very light and views can still provide this functionality. Consider the following configuration: view sorting options: table fields sortable: Result: The view always remains sorted (and grouped) by the most recent profile and profile name And I've created a patch to do just that. That's the end of the example for this patch (see attached), but in real life I actually took this further by creating a custom module that would toggle the override feature on/off depending on whether the field being click sorted was belonging to the content profile node (which would need to override/prepend/take priority/break grouping) or the job node (no need to override/can append/secondary/should remain within grouping). I love the improvements in Views 2.x over 1.x and hope this contribution will make it that much more flexible for everyone else as it has in my case! :) PS. The first line change displayed in the attached patch is also a bug fix, I'm pretty sure: If (empty($this->options['default'])) will never evaluate to TRUE because $this->options['default'] is always set to -1 when None is chosen as the Default click sort in the view, and empty(-1) === FALSE.Proposed Solution:
Benefits of this Approach:
related profile last modified, related profile author name,
node last updated date (Default)
node title
node content: location
...
Default sort order: DESC
but users can optionally control how the view is sorted beyond that e.g. by date, title, location
and nodes remained grouped in views.
| Comment | File | Size | Author |
|---|---|---|---|
| views-2.x-override.patch | 4.04 KB | ms2011 |
Comments
Comment #1
Flying Drupalist commentedsubscribe
Comment #2
merlinofchaos commentedOk, this patch is interesting.
I am confused about this part:
Why this change?
Comment #3
merlinofchaos commentedI ended up writing a different patch that may fix this issue. Check the current Views dev and see. Either way it will prevent this from applying.
Comment #4
esmerel commentedNo response to updates from merlinofchaos