0

I am writing a rather intensive ajax interface that requires me to manhandle views quite a bit. I am retrieving the results of the ajax triggers using

views_embed_view($view, $display, $arg1, $arg2);

Everything works great except the default pager ajax drops the custom info I'm dumping into views_embed_view

How can I use views_embed_view to select which pager page to return?

drupal 7, views 3

2
  • Are asking about how to do this in views on in your ajax code? – Dee May 14 '13 at 23:42
  • This is all php code. – danielson317 May 15 '13 at 0:40
2

I found the answer after a good deal of research and testing.

views_embed_view() does not have a way to do this. However, we can use the same method that views_embed_view() used.

1  $view_args = array($terms); //, $search_text
2  $view_object = views_get_view($view_name);
3  $view_object->set_current_page($offset);
4  $html = $view_object->preview($view_display, $view_args);

Line 1,2, and 3 are a simplified version of views_embed_view(). I'm bypassing permissions here so check out the function code to see how to do that part.

Line 3 is the part that sets the pager offset and solves my problem.

Note: their are two functions for setting the page offset and I used the wrong one the first time and it caused a log of confusion. The first function view->set_offset does not seem to work. I think it sets the correct value in the view object but without doing the theme and query work. so view->set_current_page is the one you want to use. I think it goes through the pager plugin to set the query and theme implications as well as set the offset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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