I have this view, a 'block' display that has ajax enabled and have a mini pager that loads next page content through ajax.
As a requirement I have to reload the current view content through ajax along with some custom sort/filter.
After going through some forums, I did something like below.
in .module page callback :
$view = views_get_view('vdlibrary');
$view->set_display('block');
$view->set_use_ajax(TRUE);
$settings = array(
'views' => array(
'ajax_path' => url('views/ajax'),
'ajaxViews' => array(
array(
'view_name' => $view->name,
'view_display_id' => $view->current_display,
'view_args' => check_plain(implode('/', $view->args)),
'view_path' => check_plain($_GET['q']),
'view_base_path' => $view->get_path(),
'view_dom_id' => 1,
//'pager_element' => $view->pager['element'],
),
),
),
);
drupal_add_js($settings, 'setting');
views_add_js('ajax_view');
in JS I am calling below ajax function on a click event to load the new views content based on the condition.
for (var key in Drupal.settings.views.ajaxViews[0]) {
data[key] = Drupal.settings.views.ajaxViews[0][key];
}
// I add additional filters/sort params to var data.
$.ajax({
url: Drupal.settings.views.ajax_path,
type: 'GET',
data: data,
dataType: 'json',
success: function(response) {
$(".vdr_container").html(response[1].data);
},
error: function() {
// handle error response.
},
});
Not surprisingly, after it loads the content, the ajax pagination feature not working instead it reloads the page along with params. How do I keep the old context or make the new loaded views to rebind pager click event to work with ajax pager.
NOTE: my descriptions might not be good enough, let me know where I could explain in better way.
Thanks