2

I have a custom AJAX app which allows the user to filter some nodes, which uses a View. By custom AJAX app, I mean that this is not just a view with AJAX enabled.

The user accesses /reports which includes the output of views_embed_view(). An AJAX-enabled browser interacts with the page, resulting in an AJAX call to /reports/ajax to fetch just the results and save a full page re-load.

It all works, except that the results returned by the View in this case use /reports/ajax as the base URL for the pager (because that's the path used to invoke the custom AJAX controller), which means that when the user clicks one, they get a page of AJAX response.

I would like to train Views to use a different URL (i.e. /reports) for pager requests. Beyond a str_replace in the output of views_embed_view(), is there another way?

1 Answer 1

1

Manually set $_GET['q'] to the appropriate value before calling views_get_view().

Views' pager uses the standard Drupal pager from includes/pager.inc which uses this request variable:

function theme_pager_link($variables) {
  // (... code omitted here ...)

  // @todo l() cannot be used here, since it adds an 'active' class based on the                                       
  //   path only (which is always the current path for pager links). Apparently,                                       
  //   none of the pager links is active at any time - but it should still be                                          
  //   possible to use l() here.                                                                                       
  // @see http://drupal.org/node/1410574                                                                               
  $attributes['href'] = url($_GET['q'], array('query' => $query));                                                     
  return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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