Count the Total Number of Results in Drupal Views

Count the Total Number of Results in Drupal Views
One of our members wondered if it was possible to automatically calculate the number of results displayed in a View.

Yes, this is definitely possible. To make this work, you will need Views, plus also the Token module installed.

Start with a long list of entries in a View, as in the image below:

List of Drupal content to be counted
  • Go to edit the view.
  • Click “Add” next to either “Header” or “Footer” in the center of the view:
Header and Footer area of Drupal views
  • Choose “Global: Result summary”
  • Click “Apply (All displays)”
Drupal views and Global: Result summary

On the next screen, you can chose tokens to put into the “Display” area. Here are the tokens you can use:

@start — the initial record number in the set
@end — the last record number in the set
@total — the total records in the set
@name — the human-readable name of the view
@per_page — the number of items per page
@current_page — the current page number
@current_record_count — the current page record count
@page_count — the total page count

Once you’ve chosen your options, click “Apply (All displays)”.

Tokens in Drupal Global Result Summary

Save your view and you’ll now see that the number of results is automatically calculated:

Drupal view with counter of total results

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
4 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Lilit Ghazaryan
Lilit Ghazaryan
6 years ago

how can i format @total result, e.g. 1.000 and 1.000.000

maria correa
maria correa
5 years ago

you can add classes, e.g.

@current_pagede @page_count

.

Abhinaw Anand
Abhinaw Anand
5 years ago

how to get total no of record in table using custom modules
https://drupal.stackexchange.com/questions/265876/how-to-get-count-of-total-record

nadeem
nadeem
4 years ago

{% set view = drupal_view_result(‘related’, ‘block_1’)|length %}
{% if view > 0 %}
{{ drupal_view(‘related’, ‘block_1’) }}
{% endif %}

4
0
Would love your thoughts, please comment.x
()
x