Skip Navigation

[Resolved] Ajax Loaded Paginated Wp-View breaks pagination

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Caridad 11 years, 2 months ago.

Assisted by: Caridad.

Author
Posts
#57536

Problem:
When a paginated view is loaded via ajax, pagination does not work because the javascript is run on document ready and the variables needed to initialize the script are loaded through a script echoed via a wp_footer hook.

Working Solution:
For the script to run, wrap the code in a global function and call it on document ready, allowing ajax plugins to execute the pagination script on demand for newly loaded content, possibly taking into account a selector context.

function wpv_pagination(context) {
	
	context = context || document;

	// Preload images in paginator initially
    jQuery('.wpv-pagination-preload-images', context).css('visibility', 'hidden');
    wpv_pagination_init_preload_images();
    jQuery('.wpv-pagination-preload-pages', context).each(function(){
        var view_number = jQuery(this).attr('id').substring(16);
        var max_pages = jQuery('#wpv_paged_max-'+view_number, context).val();
        wpv_pagination_preload_pages(view_number, 1, max_pages, false, true);
    });

	// Move the wpv_view_hash, wpv_paged_max and wpv_widget_view_id from the forms as it's only needed during ajax pagination
	jQuery('input[name=wpv_view_hash], input[name=wpv_paged_max], input[name=wpv_widget_view_id]', context).each(function(index) {
		jQuery(this).parent().after(this);
	});
}
jQuery(document).ready(function(){
	wpv_pagination();
}

For the initializing variables, instead of adding a <script> in the footer to initialize these variables, you should use the following code to initialize them in WP_Views->init() right after declaring the pagination script:

wp_localize_script( 'views-pagination-script', 'wpv_admin_ajax_url', admin_url('admin-ajax.php'));
wp_localize_script( 'views-pagination-script', 'wpv_ajax_pagination_url', $ajax_url );

I hope this fix is incorporated in a near WPViews release.

Cheerz.

#57884

Dear Ioannis

I was able to reproduce your issue and I forward the information to the developers.

Thank you for a detailed report.

Regards,
Caridad

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.