Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Drupal 7 views - sort results after they have been retrieved from database just before they are rendered. Here what type of hook need to use.Is the below hook usefull? hook_views_data_alter()

Thanks, Ramesh Babu G.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can implement hook_views_pre_render(&$view) within a custom module and manipulate the result array available in $view->result:

/**
 * Implementation of hook_views_pre_render()
 *
 * @param view $view
 */
function YourModuleName_views_pre_render(&$view) {
  // Check if this is the view and display you want to manipulate
  // NOTE: Adjust/Remove the display check, if you want to manipulate some/all displays of the view
  if ('YourViewName' == $view->name && 'YourDisplayName' == $view->current_display) {
    // EXAMPLE: Just reverse result order
    // TODO: Replace with your desired (re)ordering logic
    $view->result = array_reverse($view->result);
  }
}
share|improve this answer
    
Hi Tanay Sai,Thanks for your response...Can please send me possible sort criteria list like array_reverse()...Actually here each of the result having one integer value..based on that value I have to sort the result .. –  Ramesh Babu Dec 5 '12 at 12:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.