Forums › Forums › Search & Filter Pro › Beaver Builder Masonry Grid Layout
Tagged: ajax, Beaver Builder, masonry
- This topic has 7 replies, 2 voices, and was last updated 5 years, 6 months ago by Trevor.
-
Anonymous(Private) May 15, 2019 at 12:15 am #211223
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/
Anonymous(Private) May 15, 2019 at 11:20 am #211243Yes 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.
Trevor(Private) May 15, 2019 at 11:35 am #211247Is this post of any help?
https://support.searchandfilter.com/forums/topic/mansonry-and-ajax-issues/page/2/#post-190942
Anonymous(Private) May 17, 2019 at 2:54 am #211511Got 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.
Anonymous(Private) May 18, 2019 at 12:05 am #211639So 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-modules2) Change the markup to move pagination in
frontend.php
in the new overridden module…
https://gist.github.com/neilgee/938e8e3b66ad759edbeb02a27f0339fc3) Overview tutorial…
https://wpbeaches.com/add-search-filter-pro-with-ajax-reload-to-beaver-builder-post-masonry-grid/ -
AuthorPosts