Paginate a grouped Drupal view

16 Jun 2025
Symbolic graphic of a grouped paginated Drupal view

Solving Pagination for Grouped Content

In Drupal Views, "grouping" refers to the feature found in the Format section's Style options. When configuring a view's format (Table, HTML List, Grid, etc.), you can select one or more fields to group results by. This creates visual sections with headers for each unique field value, organizing content into logical categories.

The Problem

Standard Views pagination in Drupal operates on individual rows, without awareness of the grouping structure. This results in a broken, inconsistent pager with groups split across multiple pages.

The Solution

Views Grouping Field Pager treats each group as a pagination unit rather than each row. This ensures:

  • Groups remain intact across pages
  • The pager navigation works as expected displaying the correct number of items

Use Cases

  • Project libraries grouped by category
  • News articles organized by date
  • Product catalogs grouped by type
  • Event listings arranged by date
  • Research collections organized by topic

Technical Implementation

The module:

  • executes a count view to analyze the full result set,
  • calculates the proper offset and limit values to display complete groups on each page,
  • provides pagination controls similar to Views' full pager.

Usage

  1. Create a view and add a grouping field in the format settings
  2. Set the pager to the grouping field pager, set elements per page
  3. Optionally specify the grouping field, or let the module detect it from your view's grouping settings

Caveats

  • Only tested with one grouping field (views allows grouping by two fields).
  • There is a performance impact as the view is executed twice. However, the first execution only retrieves structural data, so the overhead should be minimal.

Conclusion

What's with all the conclusions in blog posts? This is a technical write-up. 😅

Grab the module if you need it and write a comment down below.

Add new comment

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang target> <em> <strong> <cite> <blockquote cite> <pre> <ul type> <ol start type> <li> <dl> <dt> <dd> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Get a quote in 24 hours

Wether a huge commerce system, or a small business website, we will quote the project within 24h of you pressing the following button: Get quote