Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views - Reload, Refresh, Re-render | How to? #1010

Open
signalpoint opened this issue Jan 18, 2018 · 3 comments
Open

Views - Reload, Refresh, Re-render | How to? #1010

signalpoint opened this issue Jan 18, 2018 · 3 comments

Comments

@signalpoint
Copy link
Owner

Today I ran into the need (yet again) to refresh a View after a custom form is submitted, (i.e. the view was already on the page and the form is building custom exposed filters to be appended to the path of the View that I want to refresh).

Here's a handy function that removes the View from DrupalGap, so it can be reloaded/refreshed/re-rendered (place this in a custom DG7 module):

function dgRemoveView(viewId) {

  // Remove the existing view from the DOM.
  $('#' + viewId).remove();

  // Remove the view from DrupalGap's internal tracker.
  var views = drupalgap.views;
  var index = views.ids.indexOf(viewId);
  if (index != -1) { views.ids.splice(index, 1); }

  // Remove the pageshow event so it can fire again.
  var events = drupalgap.page.jqm_events;
  index = events.indexOf("pageshow-_theme_view-" + viewId);
  if (index != -1) { events.splice(index, 1); }

}

Then for example, you can remove the view then re-append it to the content region:


// Remove the view from the DOM.
dgRemoveView('my-view-id');

// Get the new html ready.
var content = {};
content.my_view = { /*... A Views Render Array using the same id "my-view-id" ... */ };
var html = drupalgap_render(content);

// Append the html to the content region.
var selector = '#' + drupalgap_get_page_id() + ' .region_content';
$(selector).append(html).trigger('create');

A little hacky, but it gets the job done! I'll plan to move dgRemoveView() into DG7 core eventually, give it a new name, and an appropriate home in the docs.

@zak-schlemmer
Copy link
Contributor

Would this be at all relevant to the issue I encountered with dg8 views in a form not getting to formState?

@signalpoint
Copy link
Owner Author

Negative ghost rider, dg7 only.

@zak-schlemmer
Copy link
Contributor

Cool, it actually has not been that bad to detect the various selections thus far manually.
Just thought I'd check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants