DrupalGap
DrupalGap copied to clipboard
Views - Reload, Refresh, Re-render | How to?
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.
Would this be at all relevant to the issue I encountered with dg8 views in a form not getting to formState?
Negative ghost rider, dg7 only.
Cool, it actually has not been that bad to detect the various selections thus far manually. Just thought I'd check.