Note: I have requested that this be added to Advanced Help in the Views module - see http://drupal.org/node/495626

To alter a view before it is rendered we can use hook_views_pre_render(&$view).
To view a list of views api refer to http://api.drupal.org/api/views/views.api.php/group/views_hooks/7 .

To use this function we must add this function to the module file

function modulename_views_pre_render(&$view) {

}

Just to make sure you only alter the view you want we will add a condition at the very top of this function to check if it is correct view.
Suppose your view name is "foobar". Then the code will look something like this.

function modulename_views_pre_render(&$view) {
  if($view->name == "foobar") {
      //Add code to manipulate the view
  }
}

To view an example of how to alter a view footer check this out
http://drupal.org/node/422264#comment-1466510

Comments

scottprive’s picture

This looks like a good start, but I think that many people looking for an example of hook views pre_render() are going to end up here, and end up going no further. Currently on the web, there are exactly zero (0) tutorials or examples on hacking views pre_render. The linked issue is helpful but limited.

Those who know, perhaps a working example would help. (The issues queue contains many cases of users looking to filter views results due to duplicate fields in rows [a JOIN issue], or looking to dynamically set view title using fields from results).

agungsuyono’s picture

Alternatively, you can also alter views before cached in database using hook_views_default_views_alter(&$views). More hook on views is documented in views/docs/docs/php and also in http://views.doc.logrus.com/group__views__hooks.html.