Magento – Magento 2 Ajax pagination for grid on front end

frontendmagento2

On custom tab of product detail page on front end i have added a table and used Pager for pagination.

Magento\Theme\Block\Html\Pager

But this reloads the entire page when pagination is used. I don't want to reload the entire page.

Is their any way to use ajax along with Pager?

If not then can you recommend some other way around?

Thanks.

Best Answer

There are some good infinite scroll plugins. Not sure about ajax pagination but could be done by creating a controller that just returns the layout of the product grid and returns the ajax and replaces the block each time.

This https://github.com/czone-tech/magento2-ajaxified-catalog has a good starting point atleast and may of even done ajax pagination (the demo currently isn't working and i cant remember). But with that if it doesn't have it you could just add some javascript and update the links so they just run some ajax query on the pagination to pull the correct page (just add ajax=1 parameter) and replace the response with the product list element from there.

I have created ajax search and infinite scroll pretty easily with this so pagination shouldn't be a problem.

Related Topic