Skip Navigation

[Resolved] Scroll to top after pagination

This thread is resolved. Here is a description of the problem and solution.

Problem:
When I paginate a View, the View will not scroll automatically to its first results in the List (top) but stay where I was previously in the List.
How can I make Views scroll always to the Top after pagination?

Solution:
1. Head to the View in question
2. Find the Parametric Filter Editor and open the JS Tab
3. Click on the Button "Frontend events"
4. Find the hook you need (in your case, Pagination > The AJAX pagination has been completed)
5. Insert the hook and populate it with Custom Code to scroll to the top.

An example of such Custom Code can be found here:

jQuery('html, body').animate({ scrollTop: 0 }, 'fast');

==> Do use jQuery instead of $
WordPress requires you to use standard namespace instead of $
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/

Relevant Documentation:
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/

This support ticket is created 7 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by renanC-2 7 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#404263

I am trying to get views to scroll to the top after the pagination with AJAX is completed.

I tried using the following code that I found in another topic here in the forum:

 jQuery(document).on('click','.wpv-filter-previous-link,.wpv-filter-next-link', function() {
$('html, body').animate({ scrollTop: 0 }, 'fast');
});

But when I insert this code, the pagination reloads the whole page, instead of just updating the view with AJAX.

How do I get the AJAX effect and scroll to the top of page?

You can see my page in this URL: hidden link

#404439
Parametric Search JS Section - Open frontend events.png
Insert Pagination Hook.png

You do use the wrong hook.

See, Views provided some great Custom JS Hooks some cycles ago.
This can be used to add Custom JS Events as yours to a specific Event triggered on the front end, such as Search Updates or pagination.

To solve your issue, you can follow as this:

1. Head to the View in question
2. Find the Parametric Filter Editor and open the JS Tab
3. Click on the Button "Frontend events"
4. Find the hook you need (in your case, Pagination > The AJAX pagination has been completed)
5. Insert the hook and populate it with your Code

==> Do use jQuery instead of $
WordPress requires you to use standard namespace instead of $
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/

This works, I tested it.

The Pagination will be triggered by AJAX, and the page won't be reloaded.

==> You will need to update your Toolset first, to have this working.

Please also consult my ScreenShots.

#404511

Thanks, it worked.

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