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?

CommentFileSizeAuthor
#4 groupinglimit-1410718-4.patch2.37 KBbones
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

There 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.

samw’s picture

Would 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

bones’s picture

Would 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...

bones’s picture

Status: Active » Needs review
FileSize
2.37 KB

I 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.

Status: Needs review » Needs work

The last submitted patch, groupinglimit-1410718-4.patch, failed testing.

anavrin’s picture

Status: Needs work » Needs review

#4: groupinglimit-1410718-4.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, groupinglimit-1410718-4.patch, failed testing.

trackleft’s picture

Status: Needs work » Needs review

#4: groupinglimit-1410718-4.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, groupinglimit-1410718-4.patch, failed testing.

trackleft’s picture

When 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.

mitsugo’s picture

Issue summary: View changes

Any updates to this patch? I'm really interested in this functionality. I'm working on something very similar.

Regards,

Tommy