Mansonry and AJAX Issues

Forums › Forums › Search & Filter Pro › Mansonry and AJAX Issues

Tagged: ,

Viewing 3 posts – 11 through 13 (of 13 total)
  • Trevor
    #190937

    Great to speak with you Kirk. You are going to have a look and see if this code example is of any use to you:

    <script>(function ($) {
        
    	function loadMasonry(){
    
    		//$container will always be a new copy
    		var $container = $('.ae-post-widget-wrapper');
    		
    		//running images loaded again after page load / ajax event 
    		$container.imagesLoaded(function () {
    			// INITIALIZE MASONRY
    			$container.masonry({
    				itemSelector: '.entry',
    				columnWidth: '.entry',
    				gutter: 40,
    			});
    			// Masonry has been initialized, okay to call methods
    			
    			// not sure if you will need this here but might be worth adding in
    			//$container.masonry('reloadItems');
    		});
    	}
    	
    	
    	//then also call it after ajax event
    	$(document).on("sf:ajaxfinish", ".searchandfilter", function () {
    		console.log("ajax complete");
    		loadMasonry();
    	});
    
    }(jQuery));</script>
    Anonymous
    #190942

    Hi Trevor,

    The code you’ve provided has helped me re-initiate the masonry grid after a search has taken place, which was another problem that I need to overcome.

    I’ve modified the code slightly for responsiveness…

    
    (function ($)
     {
        
    	"use strict";
    	
    	function loadMasonry(){
    		
    		//$container will always be a new copy
    		var $container = $('.search-filter-results-list');
    		
    		//running images loaded again after page load / ajax event 
    		$container.imagesLoaded(function () {
    			// INITIALIZE MASONRY
    			$container.masonry({
    				itemSelector: '.search-filter-result-item',
    				columnWidth: '.grid-sizer',
    				gutter: '.gutter-sizer',
    				percentPosition: true,
    				horizontalOrder: true
    			});
    			// Masonry has been initialized, okay to call methods
    			
    			// not sure if you will need this here but might be worth adding in
    			//$container.masonry('reloadItems');
    		});
    	}
    	
    	
    	//then also call it after ajax event
    	$(document).on("sf:ajaxfinish", ".searchandfilter", function () {
    		console.log("ajax complete");
    		loadMasonry();
    	});
    
    	//an event fired when S&F is initialised and S&F scripts have been loaded
    	$(document).on("sf:init", ".searchandfilter", function(){
    		console.log("S&F JS initialised");
    		loadMasonry();
    	});
    
    	
    }(jQuery));
    

    I’m still having issues with the next items loading in via AJAX in a masonry layout though.
    https://mgg.devrap.co.uk/

    I’m currently investigating, but if you have any further suggestions, please let me know.

    Thanks for your time so far.

    Regards,

    Kirk

    Anonymous
    #190978

    Hi Trevor,

    I’ve now added the following and masonry and AJAX is working…

    
    $container.masonry('reloadItems');
    

    I’ve placed this here…

    
    		$container.imagesLoaded(function () {
    			// INITIALIZE MASONRY
    			
    			$container.masonry('reloadItems');
    			
    			$container.masonry({
    

    Thanks again for your assistance.

    Regards,

    Kirk

Viewing 3 posts – 11 through 13 (of 13 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.