I have a rule link in a view that, along with other things, deletes the node. Is there a way to trigger a view refresh after the rule link has been clicked - similar to the views flag refresh module?

Comments

jelhan’s picture

Issue summary: View changes

I did not tested it, but what's about you just using an page redirect action on the rule which points to the same page? Shouldn't this work as a refresh?

bennos’s picture

yeah this works, but it reload the complete page new.

what bjalford means is a ajax refresh of only the view itself.

sounds interesting

fishfree’s picture

subscribe

loparr’s picture

Yes there is a way.
Just use this code inside your custom js file. Replace your_view_id with a desired view.

(function ($) {
    Drupal.behaviors.blockRefresh = {
        attach: function (context, settings) {
            jQuery('.rules-link').once().click(function () {
                    jQuery.each(Drupal.views.instances, function (i, view) {
                        var selector = '.view-dom-id-' + view.settings.view_dom_id;
                        if (view.settings.view_display_id == "your_view_id") {
                            console.log('1');
                            jQuery(selector).triggerHandler('RefreshView');
                        }
                        jQuery(selector).unbind();
                    });
                });

        }
    }
}(jQuery));
Yuri’s picture

Here is another vote for the ajax refresh feature.
It might be interesting to look how the flag module has solved the same issue with this module:
https://www.drupal.org/project/views_flag_refresh

kopeboy’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Yep, don't we have everything we need?

I am not a developer and I've never done a module or a patch, but I would like to help :(
This would be very useful.

maxplus’s picture

thanks @loparr, your code works for me.

For people who don't know where to find your_view_id, read this: https://www.drupal.org/node/1259304
=> I set my view to a display_id of my own choice instead of the default chosen by Views

I also had another problem that Rules links keeps redirecting to my front page but after I used the current DEV version and set it to "javascript", that problem was also solved (see https://www.drupal.org/node/2630304 and https://www.drupal.org/node/2549881#comment-11900104)

Anonymous’s picture

If somebody else is fighting with the code from #4 only refreshing the view after the second click here is how I got it working:

(function ($) {
  Drupal.behaviors.blockRefresh = {
    attach: function (context, settings) {
      jQuery(document).ready(function () {
        jQuery('.rules-link').once().click(function () {
          jQuery.each(Drupal.views.instances, function (i, view) {
            var selector = '.view-dom-id-' + view.settings.view_dom_id;
            if (view.settings.view_display_id == "MY_VIEW_ID_WHICH_IS_THE_MACHINE_NAME_OF_THE_VIEW" ) {
                jQuery(selector).triggerHandler('RefreshView');
                }
              jQuery(selector).unbind();
          });
        });
      });
    }
  }
}(jQuery));

Modification is only to add the (document).ready function above the click function.