Download & Extend

Add documentation for get_total_rows option

Project:Views
Version:6.x-3.x-dev
Component:Documentation
Category:task
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

The flag $view->get_total_rows is used to force the query of the view to calculate the total number of results of the set.
This parameter is TRUE by default in views that get all the results (no limit) or those which have a pager, so you always have the $view->total_rows variable populated in those cases.
But when you have a view that gets only a given number of results and no pager, the count query is not executed by default so you have to force it, i.e. in the hook_views_pre_execute so you have $view->total_rows populated for later use.
<?php
function my_module_views_pre_execute(&$view) {
if ($view->name == 'my_view' && $view->current_display == 'my_display') {
$view->get_total_rows = TRUE;
}
}
>?

I think this should be documented, but not sure where.

Comments

#1

Sorry, misspelled the php code:

<?php
function my_module_views_pre_execute(&$view) {
  if (
$view->name == 'my_view' && $view->current_display == 'my_display') {
   
$view->get_total_rows = TRUE;
  }
}
?>

#2

Version:7.x-3.x-dev» 6.x-3.x-dev

This can also be used for 6.x

#3

Do you want to create a patch? This would be awesome.

#4

I do, but im not sure of which file i should patch, where do you think this should be placed?

#5

Status:active» fixed

pushed to 3.x

#6

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.