I made an edit to the page to remove the shortcode element and replace it with a Text element, with this in it:
[searchandfilter id="2017"][searchandfilter id="2017" action="filter_next_query"]
<script>(function ( $ ) {
"use strict";
// detects when the ajax request has finished and the content has been updated
// re-init the layout scripts from Elementor
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
elementorFrontend.hooks.doAction('frontend/element_ready/posts.cards', jQuery('.elementor-widget-posts'));
});
}(jQuery));</script>
I also enabled Masonry for the Post Grid (without which there is an issue with images).
AnonymousInactive
Hi Trevor,
1. Update on the “ajax complete” issue
I used the following code and the masonry is reloaded now. Not sure if it is the best solution though. Please feel free to advise.
$(document).ajaxComplete(function() {
loadMasonry();
});
2. Slow loading speed on mobile
I unchecked the options “Post Type Archives”, “Tag, Category & Taxonomy Archives” and “Author Archives” on the settings page and the page speed has instantly improved on mobile. Are there any other options that I can turn off to improve the page speed further?
Thanks,
Anna
Is it even logging ajax complete to the console? If it is not, then the code may need to be different. Assuming the loadMasonry function finishes before the loadMasonry() call, our code would need to be this:
(function ( $ ) {
"use strict";
$(document).on("sf:ajaxformfinish", ".searchandfilter", function(){
console.log("ajax complete");
loadMasonry();
});
}(jQuery));
It might be a number of things, but most likely you have one or both of:
Lazyload images (such as in Jetpack; it is an option you can disable)
the grid might be ‘powered’ by Masonry (Isotope), in which case the grid would need to have the Masonry script re-triggered to re-build the grid correctly.
Are you able to send me a live link/URL to your search page so I can take a look?
Are you using Masonry in Post Grid?
AnonymousInactive
So this is only needed when masonry is used as the layout, the above javascript is used to recreate the masonry after an Ajax reload but the pagination fails – as the pagination is outside of the main post masonry grid.
1) Override the BB Post Grid Module…
https://kb.wpbeaverbuilder.com/article/624-cmdg-18-override-built-in-modules
2) Change the markup to move pagination in frontend.php in the new overridden module…
https://gist.github.com/neilgee/938e8e3b66ad759edbeb02a27f0339fc
3) Overview tutorial…
https://wpbeaches.com/add-search-filter-pro-with-ajax-reload-to-beaver-builder-post-masonry-grid/
AnonymousInactive
Got it working with the help of BB support…
jQuery(document).ready(function($){
// detects the end of an ajax request being made
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
refreshGridLayout();
});
/**
* Public method for refreshing Masonry within an element
*
* @since 1.8.1
* @method refreshGridLayout
*/
function refreshGridLayout() {
var $element = $( '.fl-module-post-grid' ),
msnryContent = $element.find('.masonry'),
postItem = $element.find('.fl-post-grid-post');
if ( msnryContent.length ) {
$element.imagesLoaded(function () {
msnryContent.masonry('reloadItems');
msnryContent.masonry('layout');
postItem.css('visibility', 'visible');
});
}
});
The pagination becomes borked but by overriding the post-grid module and moving the pagination markup into the main fl-post-grid container fixes it up.
AnonymousInactive
Yes trying with some support on Beaver Builder slack but not there yet – this is where I am up to…
/**
* Public method for refreshing Masonry within an element
*
* @since 1.8.1
* @method refreshGridLayout
*/
function refreshGridLayout() {
var $element = $( '.fl-post-grid' ),
msnryContent = $element.find('.fl-post-grid-post');
//running images loaded again after page load / ajax event
$element.imagesLoaded(function () {
// INITIALIZE MASONRY
$element.masonry({
itemSelector: '.fl-post-grid-post',
columnWidth: '.fl-post-grid-post',
gutter: 40,
});
$element.masonry('reloadItems');
});
}
I can see the callbacks working via console log alerts but the masonry layout is not rebuilt and no JS errors via console.
AnonymousInactive
Hi,
Any thoughts on how to refresh Masonry layout from a Beaver Builder Posts Module Layout with Masonry – currently layout is not refreshed after call and appears blank.
I am trying to hook a callback like so…
// detects the end of an ajax request being made
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
refreshGridLayout();
});
/**
* Public method for refreshing Masonry within an element
*
* @since 1.8.1
* @method refreshGridLayout
*/
function refreshGridLayout() {
var $element = $( '.fl-module-post-grid' );
msnryContent = $element.find('.masonry');
if ( msnryContent.length ) {
msnryContent.masonry('layout');
}
}
Example – https://tovo.websitelove.net/lights/
This is some sample code to re-load masonry/Isotope:
<script>(function ( $ ) {
"use strict";
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
// so load your masonry script here again
});
}(jQuery));</script>