I've currently got a view which groups events by day, and returns the next 10 upcoming events (Use pager: Display a specified number of items | 10 items), but was wondering if there is any way of setting the pager to show only a specified number of groups, rather than a specified number of records as is currently the case.
In this instance, I'd like to show the complete list of upcoming events for the next 2 days for which there are events (I realise I could use a filter and relative date: +2 days, but this could potentially return 0 results if there are no events over these 2 days).
Is there currently a way of returning a number of groups? If so, how would I go about achieving it?
Comment | File | Size | Author |
---|---|---|---|
#4 | groupinglimit-1410718-4.patch | 2.37 KB | bones |
Comments
Comment #1
dawehnerThere is actually no way to do that, as the groups are based on the output of fields, which can't be counted in sql directly.
For certain fields having just a single database value would be enough but for examples date fields are stored as seconds, so you would pretty complex things to get just the "date" of an event.
I really fear this is impossible to implement.
Comment #2
samw CreditAttribution: samw commentedWould this be theoretically possible using some sort of secondary view which returns the first 2 rows of the grouping field before using that as a contextual filter on the other view?
Or would this be a really inefficient way of doing things and should I just settle for second best?
Thanks
Comment #3
bones CreditAttribution: bones commentedWould also be very interested in this. Likewise I am grouping date fields.
If this can't be done at query level can it not be done at the output level? Since this is where the groups are formed anyway...
Comment #4
bones CreditAttribution: bones commentedI have managed to achieve this but perhaps quite crudely. See attached patch.
This puts an extra field in the grouping settings to 'limit' the group to a certain number (a bit like the pager). This limit can be applied at any level of groups, but will only effect its own branch. Obviously the main pager will continue to work also to limit the total number of rows, so should be set to unlimited (or a high number that seems appropriate).
Not sure if this should be included in Views or to be provided by a new plugin? Hope it is useful either way.
PS I have also added an extra 'field' variable to the theme template to aid theming. Which is unrelated to this particular issue.
Comment #6
anavrin CreditAttribution: anavrin commented#4: groupinglimit-1410718-4.patch queued for re-testing.
Comment #8
trackleft CreditAttribution: trackleft commented#4: groupinglimit-1410718-4.patch queued for re-testing.
Comment #10
trackleft CreditAttribution: trackleft commentedWhen I add this in views 7.x.3.5 I get this notice Notice: Undefined index: limit in views_plugin_style->options_form() (line 237 of /Applications/MAMP/htdocs/arizona/sites/all/modules/views/plugins/views_plugin_style.inc).
And the grouping limit doesn't happen.
Comment #11
mitsugo CreditAttribution: mitsugo commentedAny updates to this patch? I'm really interested in this functionality. I'm working on something very similar.
Regards,
Tommy