There is a nice event to trigger view reload.
Simple call $('.view.view-some-id').trigger('RefreshView'); handles all automatically.

But there is one small bug: if pager is enabled, view reloads as if the last pager link was clicked.

js/ajax_view.js line 63

  // Add the ajax to pagers.
    // Don't attach to nested views. Doing so would attach multiple behaviors
    // to a given element.
    .filter(jQuery.proxy(this.filterNestedViews, this))
    .once(jQuery.proxy(this.attachPagerAjax, this));

  // Add a trigger to update this view specifically.
  var self_settings = this.element_settings;
  self_settings.event = 'RefreshView';
  this.refreshViewAjax = new Drupal.ajax(this.selector, this.$view, self_settings);

attachPagerAjax function alters this.element_settings for each pager link.
So var self_settings = this.element_settings; receives same settings as the last processed pager link.

Swapping this two parts of code solves the problem, patch attached.

Members fund testing for the Drupal project. Drupal Association Learn more


lunazoid’s picture

Status: Needs review » Reviewed & tested by the community

I was noticing the same issue, and the patch resolved the problem.

lunazoid’s picture

Status: Reviewed & tested by the community » Needs work

Scratch my last comment. It appears that when this patch is applied, it breaks the ajax pager.

phponwebsites’s picture

I've also same issue. I tried to add this patch but ajax pager is not working. Is any other solutions to solve this problem?

Niremizov’s picture

Confirm, after applying this patch ajax pager - works as normal (not ajax) pager.

Niremizov’s picture

Niremizov’s picture

404 bytes
None View

Attached patch fixes issue partially. Pager behaviour fixed, but after triggering RefreshView filters are not applied. Also solution looks crappy, but that is for now.

edodusi’s picture

Patch in #6 only force the view to be refreshed with pager 0, which can be ok but it's not the main issue.
I've done some debugging and it seems to me that after refreshing a view with a pager, the argument settings here remains unchanged even if you apply new arguments or filters:

Drupal.views.ajaxView = function(settings) {...}

So after you refresh a view with pager, you cannot filter anymore.
It seems a very strange behavior and I was not able to patch it correctly, so for now, I cannot use the handler 'RefreshView' and a pager.

edodusi’s picture

Found a hack but it doesn't work well.

edodusi’s picture

Before calling $(view_selector).triggerHandler('RefreshView'); I save my current filters:

Drupal.settings.views.ajaxViews['views_dom_id:' + dom_id].current_view_args = myCurrentArgs;

Then in ajax_view.js I apply the patch in #6 and recover my saved args:

   self_settings.event = 'RefreshView';
+ = 0;
+  if(Drupal.settings.views.ajaxViews['views_dom_id:' + settings.view_dom_id].current_view_args) {
+    self_settings.submit.view_args = Drupal.settings.views.ajaxViews['views_dom_id:' + settings.view_dom_id].current_view_args;
+  }
   this.refreshViewAjax = new Drupal.ajax(this.selector, this.$view, self_settings);

First click on refresh link that returns a result with pager, view refreshed, pager 0.
Second click on refresh link that returns a result with or without pager, view NOT refreshed, pager 0.
Third click on refresh link that returns a result with or without pager, view refreshed, pager 0.

Hope this helps.

ctmun’s picture

In Drupal.views.ajaxView.prototype.attachPagerLinkAjax function, make a copy of this.element_settings to use within the function instead of altering it directly.

js/ajax_view.js replace line 124-125 with:

  var pager_settings = $.extend({}, this.element_settings);
  pager_settings.submit = viewData;
  this.pagerAjax = new Drupal.ajax(false, $link, pager_settings);
ctmun’s picture

821 bytes
None View

Attaching patch with changes to js/ajax_view.js for testing.

ctmun’s picture

Status: Needs work » Needs review
matysek145’s picture

I had same problem with Views Load More module.
With patch #11 everything works fine - thanks!

edodusi’s picture

I can confirm thath the patch in #11 fixes the issue.

cvharris’s picture

Can confirm #11 works for me too!

maximpodorov’s picture

New module is released for views reloading:

Huntelaer’s picture

#11 Also solved my problem with a table view which was automatically sorted after triggering 'RefreshView'

daveferrara1’s picture

daveferrara1’s picture

ugintl’s picture

Instead of updating the view, how to show a link "Click to see new items". When user clicks, it should then update the view with new items. I am using statuses module which shows status updates of a user and it has built-in refresh AHAH, but it is not working.